Module library.script.bpl_libraries

Expand source code
import json

import pandas as pd
import requests

from . import df_to_tempfile


class Scriptor:
    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)

    def ingest(self) -> pd.DataFrame:
        url = "https://www.bklynlibrary.org/locations/json"
        response = requests.get(url)
        content = json.loads(response.content)
        data = []
        for i in content["locations"]:
            data.append(i["data"])
        df = pd.DataFrame.from_dict(data, orient="columns")
        return df

    def runner(self) -> str:
        df = self.ingest()
        local_path = df_to_tempfile(df)
        return local_path

Classes

class Scriptor (**kwargs)
Expand source code
class Scriptor:
    def __init__(self, **kwargs):
        self.__dict__.update(kwargs)

    def ingest(self) -> pd.DataFrame:
        url = "https://www.bklynlibrary.org/locations/json"
        response = requests.get(url)
        content = json.loads(response.content)
        data = []
        for i in content["locations"]:
            data.append(i["data"])
        df = pd.DataFrame.from_dict(data, orient="columns")
        return df

    def runner(self) -> str:
        df = self.ingest()
        local_path = df_to_tempfile(df)
        return local_path

Methods

def ingest(self) ‑> pandas.core.frame.DataFrame
Expand source code
def ingest(self) -> pd.DataFrame:
    url = "https://www.bklynlibrary.org/locations/json"
    response = requests.get(url)
    content = json.loads(response.content)
    data = []
    for i in content["locations"]:
        data.append(i["data"])
    df = pd.DataFrame.from_dict(data, orient="columns")
    return df
def runner(self) ‑> str
Expand source code
def runner(self) -> str:
    df = self.ingest()
    local_path = df_to_tempfile(df)
    return local_path