def get_bulk_vector_data_by_range(vectors, start_release_date, end_release_date): """https://www.statcan.gc.ca/eng/developers/wds/user-guide#a12-5 Parameters ---------- vectors: str or list of str vector numbers to get info for start_release_date: datetime.date start release date for the data end_release_date: datetime.date end release date for the data Returns ------- List of dicts containing data for each vector """ url = SC_URL + "getBulkVectorDataByRange" start_release_date = str(start_release_date) + "T13:00" end_release_date = str(end_release_date) + "T13:00" chunks = chunk_vectors(vectors) final_list = [] for vector_ids in chunks: result = requests.post( url, json={ "vectorIds": vector_ids, "startDataPointReleaseDate": start_release_date, "endDataPointReleaseDate": end_release_date, }, ) result = check_status(result) final_list += [r["object"] for r in result] return final_list
def get_data_from_vectors_and_latest_n_periods(vectors, periods): """ https://www.statcan.gc.ca/eng/developers/wds/user-guide#a12-4 Parameters ---------- vectors: str or list of str vector numbers to get info for periods: int number of periods (starting at latest) to retrieve data for Returns ------- List of dicts containing data for each vector """ url = SC_URL + "getDataFromVectorsAndLatestNPeriods" chunks = chunk_vectors(vectors) final_list = [] for chunk in chunks: periods_l = [periods for i in range(len(chunk))] json = [{ "vectorId": v, "latestN": n } for v, n in zip(chunk, periods_l)] result = requests.post(url, json=json) result = check_status(result) final_list += [r["object"] for r in result] return final_list
def get_series_info_from_vector(vectors): """https://www.statcan.gc.ca/eng/developers/wds/user-guide#a11-3 Parameters ---------- vectors: str or list of str vector numbers to get info for Returns ------- List of dicts containing metadata for each v# """ url = SC_URL + "getSeriesInfoFromVector" chunks = chunk_vectors(vectors) final_list = [] for chunk in chunks: vectors = [{"vectorId": v} for v in chunk] result = requests.post(url, json=vectors) result = check_status(result) final_list += result return [r["object"] for r in final_list]