-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__init__.py
More file actions
executable file
·44 lines (37 loc) · 1.34 KB
/
__init__.py
File metadata and controls
executable file
·44 lines (37 loc) · 1.34 KB
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
import urllib.request, urllib.error, urllib.parse
import json
import MySQLdb
import os
from xploreapi import XPLORE
from TosDao import TOSDAO
## Load configuration
con_file = open("config.json")
config = json.load(con_file)
con_file.close()
#xploreapi
xplore = XPLORE(config['apikey'])
#db
tosDao = TOSDAO(config)
publications = tosDao.getArticlesWithoutKeywords()
count = 0
try:
for publication in publications:
print("Fetching keywords for publication: ", publication.title)
xplore.articleTitle(publication.title)
articleData = json.load(urllib.request.urlopen(xplore.callAPI(False)))
if bool(articleData['articles'][0]['index_terms']):
keywords = articleData['articles'][0]['index_terms']['ieee_terms']['terms']
for key in keywords:
print(key)
tosDao.insertKeyword(keywords, publication.id)
count = count+1
except urllib.error.HTTPError as e:
if hasattr(e,'code'):
print(e.code)
if (e.code == 403):
print("API call limit has reached. Try running the script with an other API key or tomorrow")
if (e.code == 400):
print("Bad request! Check the publication title : ", (publications[count].title) )
if hasattr(e,'reason'):
print(e.reason)
print("Inserted ", int(count)," records from publications")