Created
March 29, 2023 18:42
-
-
Save leandrochiarini/202cd7e5c2d52cb7e2c45e2c9e4431db to your computer and use it in GitHub Desktop.
Command line interface to look for arxiv articles from today using fzf. It also saved all opened articles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import arxiv | |
import feedparser | |
import re | |
import os | |
from pathlib import Path | |
from pyfzf.pyfzf import FzfPrompt | |
import webbrowser | |
import argparse | |
import sys | |
# Change subject according to your preference | |
Arxiv_Subject="math.PR" | |
RE_id = re.compile(r"^([0-9v\.]+)") #Regular expression for arxiv ids | |
def main() : | |
Feed = feedparser.parse('https://export.arxiv.org/rss/'+Arxiv_Subject) | |
fzf = FzfPrompt() | |
re_titles=re.compile(r"\. \(arXiv:([0-9v\.]+) .*\)$") | |
re_authors=re.compile(r"\<a href.*\>(.*)<\/a>") | |
# TODO Add authors | |
titles = [re.search(re_titles, point.title).group(1) + "\t"+ re.sub(re_titles,"",point.title) for point in Feed.entries] | |
if len(titles)==0: | |
print("No articles found") | |
link=r"https://export.arxiv.org/rss/"+Arxiv_Subject | |
print("Opening ",link) | |
webbrowser.open(link, new = 2) | |
exit("Check internet connection, or if it is a public holiday in the US") | |
selected = fzf.prompt(titles,r" --with-nth=1.. --tac -m --preview 'arxiv-today.py {}' --preview-window=up" ) | |
if len(selected) > 0: | |
home_dir= Path.home() | |
filename = str(home_dir) | |
file_object = open(filename+'/.arxiv-history', 'a') | |
print("Files selected") | |
print("") | |
for article in selected: | |
id_article= re.search(RE_id,article).group(1) | |
title_article= article | |
link=r"https://arxiv.org/abs/"+id_article | |
print("Opening ",link) | |
webbrowser.open(link, new = 2) | |
file_object.write(article+"\n") | |
print("") | |
print("See you tomorrow!") | |
file_object.close() | |
else: | |
print( "No articles selected") | |
def preview(article_to_preview) : | |
id_article= re.search(RE_id,article_to_preview).group(1) | |
search = arxiv.Search( | |
id_list = [id_article], | |
max_results = 10, | |
sort_by = arxiv.SortCriterion.SubmittedDate, | |
sort_order = arxiv.SortOrder.Descending | |
) | |
for result in search.results(): | |
print(f"Title: {result.title}") | |
print() | |
Authors_art=[str(author) for author in result.authors] | |
print("Authors: ", ", ".join(Authors_art)) | |
print() | |
print("Abstract") | |
print(result.summary) | |
if __name__ == "__main__": | |
if len(sys.argv) == 1 : | |
main() | |
elif len(sys.argv) == 2 : | |
preview(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instruction: Just change the value of
Arxiv_Subject
to your preferred area.Notice that the script requires
arxiv.py
andpyfzf.py
, both of which can be downloaded viapip
.