Skip to content

Commit

Permalink
added citation max age
Browse files Browse the repository at this point in the history
  • Loading branch information
OllyButters committed Jul 8, 2016
1 parent f99349e commit 3accf9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 10 additions & 5 deletions source/add/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
# Use the elsevier API to get the number of citations a paper has bsed on its PMID.
# Ultimately need to build a GET string like
# http://api.elsevier.com/content/search/scopus?query=PMID(18562177)&apiKey=8024d746590aade6be6856a22a734783&field=citedby-count
def citations(papers):
def citations(papers, api_key, citation_max_life):

api_key = '8024d746590aade6be6856a22a734783'
url = 'http://api.elsevier.com/content/search/scopus'

print 'Doing citations'
Expand All @@ -24,9 +23,15 @@ def citations(papers):
with open('../cache/citations.csv', 'rb') as csvfile:
f = csv.reader(csvfile)
for row in f:
cached_citations[row[0]] = {}
cached_citations[row[0]]['citation_count'] = row[1]
cached_citations[row[0]]['date_downloaded'] = row[2]
# Parse the date the citation was cached
date_downloaded = datetime.datetime.strptime(row[2], "%Y-%m-%d %H:%M:%S.%f")

# If the citation is younger than (today - citation_max_life)
# then use it. Not using it means we will download it again.
if abs(datetime.datetime.now() - date_downloaded) < datetime.timedelta(days=citation_max_life):
cached_citations[row[0]] = {}
cached_citations[row[0]]['citation_count'] = row[1]
cached_citations[row[0]]['date_downloaded'] = row[2]
csvfile.close()
logging.info('Citation cache file read in')
except:
Expand Down
7 changes: 5 additions & 2 deletions source/papers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
__version__ = '0.2.4'


# Options
# Options - these should get moved out into a config file
# Stick a flag into see if we want to update the citations
update_citations = True
scopus_api_key = '8024d746590aade6be6856a22a734783'
scopus_citation_max_life = 30 # days


# pp = pprint.PrettyPrinter(indent=4)

Expand Down Expand Up @@ -89,7 +92,7 @@
add.geocode.geocode(papers)

if update_citations:
add.citations.citations(papers)
add.citations.citations(papers, scopus_api_key, scopus_citation_max_life)

file_name = '../data/summary_added_to'
fo = open(file_name, 'wb')
Expand Down

0 comments on commit 3accf9c

Please sign in to comment.