arXiv API
Somehow twitter @ astro_ph_EP has stopped, and I wonder if I want a bot that only looks at the specified category, so I took a look at the arXiv API.
However, the official description (https://arxiv.org/help/api/user-manual) did not work as it was ...
The error occurred below.
data = urllib.urlopen(url).read()
Is urllib old? If it is an official description, it will work if you rewrite it as follows!
import urllib.request
url = 'http://export.arxiv.org/api/query?search_query=all:electron&start=0&max_results=1'
data = urllib.request.urlopen(url).read()
import urllib.request
import datetime as dt
import re
def main():
basedate = dt.date.today()+dt.timedelta(days=-1)
previousdate = basedate +dt.timedelta(days=-1)
url_q = 'http://export.arxiv.org/api/query?search_query=submittedDate:['+previousdate.strftime('%Y%m%d')+'1400+TO+'+basedate.strftime('%Y%m%d')+'1400]+AND+(cat:astro-ph.EP)&start=0&sortBy=submittedDate&sortOrder=ascending'
data = urllib.request.urlopen(url_q).read().decode('utf-8')
#
parse = lambda a,b: re.findall("<" + b + ">([\s\S]*?)<\/" + b + ">", a)
#
entries = parse(str(data), "entry")
for entry in entries:
url = parse(entry, "id")[0]
title = parse(entry, "title")[0]
author = ', '.join(parse(entry, "name") )
summary = parse(entry, "summary")[0]
print( '%s\n%s\n%s\n%s' % (url, title, author, summary) )
if __name__ == '__main__':
main()
The number of submissions does not match the number of new submissions ... US holidays can be avoided by using holidays.US ().
Recommended Posts