Getting the arXiv API in Python

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 ...

Official fix

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()

Acquisition example

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

Getting the arXiv API in Python
Hit the Sesami API in Python
Hit the web API in Python
Access the Twitter API in Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Tweet using the Twitter API in Python
Try hitting the YouTube API in Python
Evernote API in Python
C API in Python 3
Try using the BitFlyer Ligntning API in Python
Tips for hitting the ATND API in Python
Hit the Firebase Dynamic Links API in Python
Try using the DropBox Core API in Python
Hit Mastodon's API in Python
Download the file in Python
Find the difference in Python
Blender Python API in Houdini (Python 3)
Call the API with python3.
Getting list elements in Python
Initial settings when using the foursquare API in python
Using the National Diet Library Search API in Python
Get your heart rate from the fitbit API in Python!
Python in the browser: Brython's recommendation
Save the binary file in Python
[Python] Hit the Google Translation API
Get the desktop path in Python
Get the script path in Python
In the python command python points to python3.8
Implement the Singleton pattern in Python
Hit the Etherpad-lite API with Python
Create Gmail in Python without API
Use the Flickr API from Python
I wrote the queue in Python
Calculate the previous month in Python
Examine the object's class in python
Get the desktop path in Python
Quickly implement REST API in Python
Get the host name in Python
The first step in Python Matplotlib
I wrote the stack in Python
Master the weakref module in Python
An easy way to hit the Amazon Product API in Python
Hit the New Relic API in Python to get the server status
Regularly upload files to Google Drive using the Google Drive API in Python
Play by hitting the Riot Games API in Python First half
Learn the design pattern "Prototype" in Python
Learn the design pattern "Builder" in Python
Mouse operation using Windows API in Python
Check the behavior of destructor in Python
Learn the design pattern "Flyweight" in Python
Learn the design pattern "Observer" in Python
Learn the design pattern "Memento" in Python
Learn the design pattern "Proxy" in Python
Write the test in a python docstring
Learn the design pattern "Command" in Python
OR the List in Python (zip function)
Display Python 3 in the browser with MAMP
Learn the design pattern "Visitor" in Python
Get Google Fit API data in Python
Learn the design pattern "Bridge" in Python