<jupyter_start><jupyter_text>SnapshotsSnapshots is one if the two main article delivery channels. It can be used as a one-time collection, or as an initial execution with further updates (as short as weekly). Notebook Initalization<jupyter_code>import os
from factiva.core import APIKeyUser
from dotenv import load_dotenv

load_dotenv()
aku = APIKeyUser(os.getenv("FACTIVA_APIKEY"), request_info=False)
 
print('Initialization done!')
print(aku)
aku = APIKeyUser('<KEY>', request_info=True)
aku<jupyter_output><empty_output><jupyter_text>Notebook VariablesEnsure that the value for the following variables is set according to the provided credentials and local environment.<jupyter_code>snapshot_download_dir = "data-" + "cse-NewsCO"  # Don't change the data previx and ensure this value is updated for each new snapshot collection

snapshot_query = { 'query': {
                        'where': 'publication_datetime >= "2019-01-01 00:00:00" AND publication_datetime < "2019-08-29 00:00:00" AND REGEXP_CONTAINS(UPPER(region_of_origin), r"(COL)")'
                     } }<jupyter_output><empty_output><jupyter_text>ExplainThe explain API provides count of articles to have an idea about the potential volume to be returned by the Extract (Snapshots) API. The query used in this section is exactly the same that will be used for **Analytics** and **Extractions**. Create the Explain JobExplains as well as other operations available under the Snapshots category receive a POST request with a query and an action, and the response notifies if the job was created successfully or not, along with a Job ID. Then, the Job ID has to be used as paramneter to fire a new request with the aim to obtain the operation output.<jupyter_code>expl_req_url = api_url + explain_api_path
expl_resp = requests.post(expl_req_url, headers = api_headers, json = snapshot_query)
if expl_resp.status_code < 400:
    expl_id = expl_resp.json()['data']['id']
    print("Successful Explain Request\n{0}".format(json.dumps(expl_resp.json()['data'])))
else:
    print("Failed Explain Request with code {0} and message {1}".format(expl_resp.status_code, json.dumps(expl_resp.json()['errors'])))<jupyter_output><empty_output><jupyter_text>Check the Explain Job ResultsThis operations has to be executed until the current_state field is shown as "JOB_STATE_DONE".<jupyter_code>explstatus_req_url = api_url + extract_api_path + "/{0}".format(expl_id) + "/_explain"
explstatus_resp = requests.get(explstatus_req_url, headers = api_headers)
if explstatus_resp.json()['data']['attributes']['current_state'] == "JOB_STATE_DONE":
    print("Estimated article volume is {0}".format(explstatus_resp.json()['data']['attributes']['counts']))
else:
    print("Job is still running, please try again in few seconds.")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09910873440285205, 'fraction_numerical': 0.012834224598930482, 'mean_word_length': 5.877450980392157, 'pattern_counts': {'":': 1, '<': 20, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '389690', 'license': 'MIT', 'n_tokens_mistral': 860, 'n_tokens_neox': 832, 'n_words': 277, 'path': '03-snapshots.ipynb', 'repo_name': 'miballe/factiva-analytics-process', 'size': '2832'}