summaryrefslogtreecommitdiff
path: root/fetch-entries.py
blob: 027b2955d3c8cb3161b7d8531ff97d19ed006628 (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
import os
import sys
import csv
import subprocess

import click

@click.command()
@click.option('--index', '-n', default=1, help='Index of CSV.')
def fetch_entries(index):
  keys, lines = read_citation_list(index)

  for line in lines:
    label = line[0]
    title = line[1]
    entries_fn = './datasets/scholar/entries/{}.csv'.format(title)
    print(entries_fn)
    if not os.path.exists(entries_fn):
      with open(entries_fn, 'w') as f:
        subprocess.call([
          './vendor/scholar.py',
          '-t', '-s', title, '--csv',
        ], stdout=f)
      sys.exit(1)


def read_citation_list(index):
  filename = './datasets/citations.csv'
  fn, ext = os.path.splitext(filename)
  in_fn = fn + '-' + str(index) + ext
  with open(in_fn, 'r') as f:
    reader = csv.reader(f)
    lines = list(reader)
    keys = lines[0]
    lines = lines[1:]
    return keys, lines