Created
March 18, 2016 17:17
-
-
Save GrantCuster/3b3b76be2956d642c018 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python3 | |
import numpy as np | |
import os | |
import ujson | |
from pprint import pprint as pp | |
from aylienapiclient import textapi | |
import time | |
aylien_client = textapi.Client(<id>, <key>) | |
BROWSERDIR=<insert data directory here> | |
OUTDIR='aylien_results' | |
articles=os.listdir(BROWSERDIR) | |
random_subset=np.random.choice(range(0,len(articles)),500) | |
for article in random_subset: | |
article_file='{}/{}'.format(BROWSERDIR,articles[article]) | |
results_file='{}/{}'.format(OUTDIR,articles[article]) | |
with open(article_file) as article_fd: | |
article_json=ujson.load(article_fd) | |
resp=aylien_client.Summarize({'text':article_json['text'], | |
'title':article_json['title']}) | |
pp(resp) | |
with open(results_file,'w') as outfile: | |
ujson.dump(resp,outfile) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment