def get_cas_from_airtable(secret: str, app: str, table: str): """ Get CAS from airtable. """ cas = CollectiveActions() airtable = Airtable(app, table, api_key=secret) pages = airtable.get_iter(maxRecords=1000) records = [] for page in pages: for record in page: records.append(record["fields"]) for record in records: if bool(record): cas.append( CollectiveAction(**record) ) return cas
def test_cas_sort(correctly_formatted_cas_df): """ Test that CollectiveActions is sortable. """ cas_from_df = CollectiveActions.read_from_df(correctly_formatted_cas_df) sorted_cas = cas_from_df.sort() assert sorted_cas.cas[0].date == dateparser.parse("2019-04-02").date() reverse_sorted_cas = cas_from_df.sort(reverse=True) assert reverse_sorted_cas.cas[0].date == dateparser.parse( "2019-04-10").date()
def save_cas_to_csv(cas: CollectiveActions): df = cas.to_df() df.to_csv(CSV)
def get_cas_from_csv(): df = pd.read_csv(CSV) return CollectiveActions.read_from_df(df).sort()
def get_cas_from_files(): fc = FileClient() files = fc.get_all_files() return CollectiveActions.read_from_files(files).sort()
def test_cas_read_from_df(correctly_formatted_cas_df): """ Test CollectiveActions `read_from_df` function. """ cas = CollectiveActions.read_from_df(correctly_formatted_cas_df) _test_cas(cas)
def test_ca_create_from_files(correctly_formatted_cas_files): """ Test CollectiveActions `read_from_files` function. """ cas = CollectiveActions.read_from_files(correctly_formatted_cas_files) _test_cas(cas)
def save_cas_to_json(cas: CollectiveActions, json_path: str = JSON): """ Save CAS to JSON. """ data = cas.to_dict() with open(str(json_path), "w") as outfile: json.dump(data, outfile, default=ca_json_converter, indent=4)
def save_cas_to_csv(cas: CollectiveActions, csv_path: str = CSV): """ Save CAS to CSV. """ df = cas.to_df() df.to_csv(csv_path)
def save_cas_to_files( cas: CollectiveActions, folder_path: str = ACTION_FOLDER ): """ Save CAS to action folder. """ cas.to_files(folder=folder_path)
def get_cas_from_json(json_path: str = JSON): """ Get CAS from JSON. """ df = pd.read_json(json_path) return CollectiveActions.read_from_df(df).sort()
def get_cas_from_csv(csv_path: str = CSV): """ Get CAS from CSV. """ df = pd.read_csv(csv_path) return CollectiveActions.read_from_df(df).sort()
def get_cas_from_files(folder_path: str = ACTION_FOLDER): """ Get CAS from action files. """ files = get_all_files(folder_path) return CollectiveActions.read_from_files(files, folder=folder_path).sort()
def save_cas_to_all(cas: CollectiveActions): """ update cas to json, csv, readme, and actions folder. """ save_cas_to_csv(cas) save_cas_to_json(cas) save_cas_to_readme(cas) cas.to_files()