diff options
| author | adamhrv <adam@ahprojects.com> | 2018-11-04 21:54:00 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2018-11-04 21:54:00 +0100 |
| commit | 9bcba0d02aafb34a5a9ca3db2f894f1fc95401c0 (patch) | |
| tree | 3dcaf94563498c15b56d51efc62750d0be72e01a /s2-search.py | |
| parent | ef45f3c93ffd39b57ee56db74a95f9d2dae074a8 (diff) | |
| parent | 0dc3e40434c23e4d48119465f39b03bf35fb56bd (diff) | |
.
Diffstat (limited to 's2-search.py')
| -rw-r--r-- | s2-search.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/s2-search.py b/s2-search.py new file mode 100644 index 00000000..b9e8db2d --- /dev/null +++ b/s2-search.py @@ -0,0 +1,46 @@ +import os +import sys +import csv +import subprocess +import time +import random +import re +import simplejson as json +import click +from s2 import SemanticScholarAPI +from util import * + +''' +s2 search API format: +results +matchedAuthors +matchedPresentations +query +querySuggestions +results +stats +totalPages +totalResults +''' + +@click.command() +@click.option('--index', '-n', default=0, help='Index of CSV.') +def fetch_entries(index): + keys, lines = read_citation_list(index) + s2 = SemanticScholarAPI() + for line in lines: + label = line[0] + title = re.sub(r'[^-0-9a-zA-Z ]+', '', line[1]) + entry_fn = './datasets/s2/entries/{}.json'.format(title) + if not os.path.exists(entry_fn): + results = s2.search(title) + write_json(dump_fn, results) + if len(results['results']) == 0: + print("No results for {}".format(title)) + else: + print(title) + write_json(entry_fn, results['results'][0]) + time.sleep(random.randint(10, 20)) + +if __name__ == '__main__': + fetch_entries() |
