-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpublications-updater.py
More file actions
executable file
·68 lines (58 loc) · 2.91 KB
/
publications-updater.py
File metadata and controls
executable file
·68 lines (58 loc) · 2.91 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/local/python/bin/python
# -*- coding: utf-8 -*-
# Script to automatically update:
# the publications page of the NGTS website
# (http://ngtransits.org/publications.html)
# with
# the publications from the NGTS NASA ADS library
# (https://ui.adsabs.harvard.edu/public-libraries/DPYuIo9uQN6-4suzkS0Xug)
import sys
#reload(sys)
#sys.setdefaultencoding('utf8')
import subprocess
import os
import ads
ads.config.token = 'secret token'
# Change to the correct directory
os.chdir('/Users/sam/Software/NGTS.github.io/pages/tabs')
# Generate a new publications list
fields = ["author", "first_author", "bibcode", "id", "year", "title", "pub", "volume", "page", "bibcode"]
papers = ads.SearchQuery(q="docs(library/DPYuIo9uQN6-4suzkS0Xug)", sort="date desc", rows=2000, fl=fields)
newpubs = '\n'
for paper in papers:
newpubs += ' <li style="margin-bottom:8px">\n'
newpubs += ' <a href="https://ui.adsabs.harvard.edu/abs/{}/abstract">{} et al.</a>,\n'.format(paper.bibcode, paper.first_author)
if paper.volume and paper.page:
newpubs += ' {}, {}, {}, {}<br>\n'.format(paper.year, paper.pub, paper.volume, paper.page[0])
elif paper.volume:
newpubs += ' {}, {}, {}<br>\n'.format(paper.year, paper.pub, paper.volume)
elif paper.page:
newpubs += ' {}, {}, {}<br>\n'.format(paper.year, paper.pub, paper.page[0])
else:
newpubs += ' {}, {}<br>\n'.format(paper.year, paper.pub)
newpubs += ' <i>{}</i>\n'.format(paper.title[0])
newpubs += ' </li>\n\n'
oldpubs_filename = 'publications-old.txt'
newpubs_filename = 'publications-new.txt'
with open(newpubs_filename, "w") as newpubs_:
newpubs_.write(newpubs)
# If an update is required then do it
# Check for sensible length of newpubs
if len(newpubs) > 5000:
## print('newpubs is long enough: {}'.format(len(newpubs)))
# If the ADS library has been updated (or oldpubs_filename does not exist) then update the publications webpage
diff = 1
if os.path.exists(oldpubs_filename):
## print('{} exists'.format(oldpubs_filename))
diff = subprocess.check_output("diff {} {} | wc -l".format(oldpubs_filename, newpubs_filename), shell=True)
## print('Difference: {}'.format(diff))
if diff:
## print('There has been an update.')
os.system("grep -B 10000 '<!-- Start of publications -->' publications_content.html > publications_content-new.html")
os.system("cat publications-new.txt >> publications_content-new.html")
os.system("grep -A 10000 '<!-- End of publications -->' publications_content.html >> publications_content-new.html")
os.system("mv publications_content-new.html publications_content.html")
os.system("mv publications-new.txt publications-old.txt")
os.system("git add publications_content.html")
os.system("git commit -m 'Updated publications_content.html.'")
os.system("git push")