-
Notifications
You must be signed in to change notification settings - Fork 3
/
twXiv_semantic.py
30 lines (27 loc) · 953 Bytes
/
twXiv_semantic.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
#!/usr/bin/env python3
# written by So Okada [email protected]
# a part of twXiv
# https://github.com/so-okada/twXiv/
import re
import time
from ratelimit import limits, sleep_and_retry, rate_limited
from variables import *
from semanticscholar import SemanticScholar
sch = SemanticScholar(timeout=5)
@sleep_and_retry
@limits(calls=sch_call_limit, period=sch_call_period)
def paperid(arxiv_id):
trial_num = 0
while trial_num < sch_max_trial:
paper = sch.get_paper(arxiv_id)
if paper == {}:
print(str(trial_num + 1) + 'th sch parse error for ' + arxiv_id)
else:
return re.sub('https://www.semanticscholar.org/paper/', '',
paper['url'])
trial_num += 1
if trial_num < sch_max_trial:
print('sleep and retry for ' + arxiv_id)
time.sleep(sch_call_sleep)
else:
raise Exception('fatal parse error for ' + arxiv_id)