Skip to content

Instantly share code, notes, and snippets.

@AaronDavidSchneider
Last active January 30, 2023 11:21

Revisions

  1. AaronDavidSchneider revised this gist Nov 4, 2021. 1 changed file with 30 additions and 11 deletions.
    41 changes: 30 additions & 11 deletions arxivtorm.py
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,17 @@

    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)
    @@ -29,43 +40,51 @@ def get_results():

    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]
    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.txt','w') as f:
    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:
    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\n")
    f.write(f"#### comments:\n > {res.comment} \n\n\n")
    summary = res.summary
    for r_key, r_val in replace_dict.items():
    summary = summary.replace(r_key, r_val)

    r = os.system('pandoc arxiv.txt -o arxiv.pdf -f gfm --pdf-engine=xelatex')
    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')
    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.txt')
    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)
    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!')
  2. AaronDavidSchneider revised this gist Nov 3, 2021. 1 changed file with 5 additions and 4 deletions.
    9 changes: 5 additions & 4 deletions arxivtorm.py
    Original file line number Diff line number Diff line change
    @@ -42,15 +42,16 @@ def get_results():
    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"# 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:
    f.write(f"\n\n----------------------------------------------\n\n")
    f.write(f"**{res.title}**\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")
    f.write(f"{res.summary}\n\n")
    f.write(f"#### comments:\n > {res.comment} \n\n\n")

    r = os.system('pandoc arxiv.txt -o arxiv.pdf -f gfm --pdf-engine=xelatex')
    if r != 0:
  3. AaronDavidSchneider revised this gist Nov 3, 2021. 1 changed file with 10 additions and 6 deletions.
    16 changes: 10 additions & 6 deletions arxivtorm.py
    Original file line number Diff line number Diff line change
    @@ -5,15 +5,19 @@
    # 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!
    # 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
    RMAPI = '/home/aaron/bin/rmapi' # CHANGE to the install directory of rmapi
    QUERY = 'cat:astro-ph.EP'

    today = datetime.now()

    def get_results():
    @@ -27,7 +31,7 @@ def get_results():
    q_day = timezone.localize(q_day)

    search = arxiv.Search(
    query = 'cat:astro-ph.EP',
    query = QUERY,
    max_results = 100,
    sort_by = arxiv.SortCriterion.SubmittedDate
    )
    @@ -53,8 +57,8 @@ def upload(filtered, yesterday, q_day, delete=True):
    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')
    os.system(f'{RMAPI} rm arxiv')
    os.system(f'{RMAPI} put arxiv.pdf')


    if __name__ == "__main__":
  4. AaronDavidSchneider created this gist Nov 3, 2021.
    66 changes: 66 additions & 0 deletions arxivtorm.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    #!/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!')