Skip to content

Instantly share code, notes, and snippets.

@AaronDavidSchneider
Last active January 30, 2023 11:21
Show Gist options
  • Save AaronDavidSchneider/11c9bae2ce33bc39c28cf16c88dea675 to your computer and use it in GitHub Desktop.
Save AaronDavidSchneider/11c9bae2ce33bc39c28cf16c88dea675 to your computer and use it in GitHub Desktop.
daily arxiv on the remarkable
#!/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 18)
# 6. change line 1 to point to your python interpreter ($ which python), make the script executable, etc.
# 7. change the QUERY variable to query arxiv to whatever you like (line 19)
# 8. 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
QUERY = 'cat:astro-ph.EP'
today = datetime.now()
replace_dict = {r'\[': r'$',
r'\(': r'$',
r'\]':r'$',
r'\)':r'$',
# '$ ':'$',
# ' $':'$',
'$\n':'$',
r'\unit':'',
}
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)
yesterday = timezone.localize(yesterday)
search = arxiv.Search(
query = QUERY,
max_results = 100,
sort_by = arxiv.SortCriterion.SubmittedDate
)
filtered = [result for result in search.results() if result.published > q_day and result.published < yesterday]
return filtered, yesterday, q_day
def upload(filtered, yesterday, q_day, delete=True):
with open('arxiv.md','w') as f:
f.write(f"\n\n=================================================\n\n")
f.write(f"# Submissions to: {QUERY}\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:
summary = res.summary
for r_key, r_val in replace_dict.items():
summary = summary.replace(r_key, r_val)
f.write("\n\n----------------------------------------------\n\n")
f.write(r"### {}".format(res.title) + "\n\n")
f.write(r"*{}*".format(', '.join([str(a) for a in res.authors]))+"\n\n")
f.write(r"{}".format(summary)+"\n\n")
f.write("#### comments:\n > "+r"{}".format(res.comment) + "\n\n\n")
r = os.system('pandoc arxiv.md -o arxiv.pdf --pdf-engine=xelatex')
if r != 0:
print('something went wrong, when creating the pdf, using gfm instead')
os.system('pandoc arxiv.md -o arxiv.pdf --pdf-engine=xelatex -f gfm')
if delete:
os.system('rm arxiv.md')
os.system(f'{RMAPI} rm arxiv')
os.system(f'{RMAPI} put arxiv.pdf')
if delete:
os.system(f'rm arxiv.pdf')
if __name__ == "__main__":
if today.isoweekday() in range(1,6):
filtered, yesterday, q_day = get_results()
upload(filtered, yesterday, q_day, delete=False)
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