Created
July 28, 2020 03:46
-
-
Save janeadams/da52c46ad1f51741711787d683222fb5 to your computer and use it in GitHub Desktop.
Sample API Request for StoryWrangler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import pandas as pd | |
import csv | |
query = "one two three four" | |
language = "es" | |
metric = "rank" | |
rt = "false" | |
r = requests.get(f"https://storywrangling.org/api/{query}?language={language}&metric={metric}&rt={rt}").json() | |
dfs = {} | |
for ngram in r['ngrams']: | |
dfs[ngram] = pd.DataFrame(r['ngramdata'][ngram]['data'], columns=['date',r['metric']]) | |
for ngram in dfs: | |
dfs[ngram].to_csv(f"{ngram}-{r['metric']}.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment