-
Notifications
You must be signed in to change notification settings - Fork 0
/
workers_tsv.py
53 lines (47 loc) · 1.73 KB
/
workers_tsv.py
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
47
48
49
50
51
52
53
from database import Publications
from papers import *
from document import *
import csv
from document import journal_articles_requests_urls,\
retrieve_documents_from_url
import os.path
def retrieve_papers_to_tsv(ptitle):
"""
:param publication:
:param filename:
:return:
"""
ptitle_f = ptitle.replace('/', ' ')
filename = 'tsv/' + ptitle_f + '.tsv'
if os.path.isfile(filename):
return
fields = ['number', 'doi', 'spage', 'epage', 'issue', 'partnum',
'publication', 'year', 'rank', 'title', 'abstract',
'authors', 'terms']
with open(filename, 'ta', newline='') as fp:
tsv_writer = csv.writer(fp, delimiter='\t')
# tsv_writer.writerow(fields)
try:
print('get publication urls', ptitle)
urls = journal_articles_requests_urls(ptitle,
articles_per_request=1000)
for url in urls:
try:
print('reading --', url)
paper_dicts = retrieve_documents_from_url(url)
paperlist = []
for pd in paper_dicts:
p = Paper(ptitle, pd)
paperlist.append(p)
paper_str_list = []
for p in paperlist:
paper_str_list.append(p.to_list())
tsv_writer.writerows(paper_str_list)
except Exception as e:
print(str(e))
except Exception as e:
print(str(e))
if __name__ == '__main__':
publications_table = Publications()
for ptitle in publications_table.get_all_publications_title():
retrieve_papers_to_tsv(ptitle)