Skip to content

Instantly share code, notes, and snippets.

@GrantCuster
Created March 18, 2016 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrantCuster/3b3b76be2956d642c018 to your computer and use it in GitHub Desktop.
Save GrantCuster/3b3b76be2956d642c018 to your computer and use it in GitHub Desktop.
#!/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