Last active
January 30, 2023 11:21
-
-
Save AaronDavidSchneider/11c9bae2ce33bc39c28cf16c88dea675 to your computer and use it in GitHub Desktop.
daily arxiv on the remarkable
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
#!/home/aaron/miniconda3/bin/python | |
# How to: | |
# 1. Get python running on your computer | |
# 2. Install arxiv: $ pip install arxiv | |
# 3. Get pandoc running! | |
# 4. Install rmapi | |
# 5. change the rmapi variable to point to the rmapi executable (line 16) | |
# 6. Setup a cron job! | |
import arxiv | |
from datetime import datetime, timedelta | |
import pytz | |
import os | |
rmapi = '/home/aaron/bin/rmapi' # CHANGE to the install directory of rmapi | |
today = datetime.now() | |
def get_results(): | |
delta_yest = 1 if today.isoweekday() != 1 else 3 # account for weekends! | |
yesterday = today - timedelta(days=delta_yest) | |
yesterday = yesterday.replace(minute=0, hour=18, second=0, microsecond=0) | |
delta_q = 1 if yesterday.isoweekday() != 1 else 3 # account for weekends! | |
q_day = (yesterday - timedelta(days=delta_q)) | |
timezone = pytz.timezone("GMT") | |
q_day = timezone.localize(q_day) | |
search = arxiv.Search( | |
query = 'cat:astro-ph.EP', | |
max_results = 100, | |
sort_by = arxiv.SortCriterion.SubmittedDate | |
) | |
filtered = [result for result in search.results() if result.published > q_day] | |
return filtered, yesterday, q_day | |
def upload(filtered, yesterday, q_day, delete=True): | |
with open('arxiv.txt','w') as f: | |
f.write(f"\n\n=================================================\n\n") | |
f.write(f"Submissions to Earth and Planetary Astrophysics\n\n") | |
f.write(f"received from {q_day.strftime('%d.%m.%Y, %H:%M')} to {yesterday.strftime('%d.%m.%Y, %H:%M')} GMT\n") | |
f.write(f"\n\n=================================================\n\n") | |
for res in filtered: | |
f.write(f"\n\n----------------------------------------------\n\n") | |
f.write(f"**{res.title}**\n\n") | |
f.write(f"*{', '.join([str(a) for a in res.authors])}*\n\n") | |
f.write(f"{res.summary}\n") | |
r = os.system('pandoc arxiv.txt -o arxiv.pdf -f gfm --pdf-engine=xelatex') | |
if r != 0: | |
print('something went wrong, when creating the pdf') | |
if delete: | |
os.system('rm arxiv.txt') | |
os.system(f'{rmapi} rm arxiv') | |
os.system(f'{rmapi} put arxiv.pdf') | |
if __name__ == "__main__": | |
if today.isoweekday() in range(1,6): | |
filtered, yesterday, q_day = get_results() | |
upload(filtered, yesterday, q_day) | |
print(f"received from {q_day.strftime('%d.%m.%Y, %H:%M')} to {yesterday.strftime('%d.%m.%Y, %H:%M')} GMT\n") | |
else: | |
print('Weekend!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment