summaryrefslogtreecommitdiff
path: root/scraper/s2-papers.py
blob: bf77a7343d751eed4b53a1789e7ebcebf0bcfb19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
'''

s2 = SemanticScholarAPI()

@click.command()
@click.option('--index', '-n', default=0, help='Index of CSV (query,)')
@click.option('--depth', '-d', default=1, help='Depth to recurse (not implemented).')
def fetch_papers(index, depth):
  keys, lines = read_citation_list(index)
  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):
      print('not found: {}'.format(entry_fn))
      continue
    result = read_json(entry_fn)
    paper_id = result['id']
    paper = fetch_paper(paper_id)
    # get all of the paper's citations

if __name__ == '__main__':
  fetch_papers()