Last active
May 26, 2021 00:30
This sends you e-mails in Japanese that report new articles whose categories interest you were submitted on arXiv. Because I made this for Japanese, I wrote some comments in Japanese. If you are interested in other categories, you can change the categories on the code according to https://arxiv.org/help/prep#subj . If you want to receive the e-m…
This file contains hidden or 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
import arxiv | |
import datetime | |
from googletrans import Translator | |
import requests | |
import time | |
translator = Translator() | |
# パラメータの設定 | |
# WebhookのURL | |
API_URL = "Webhook_URL" | |
# クエリの設定(カテゴリ) | |
QUERY_cat = "(cat:astro-ph.CO OR astro-ph.GA)" | |
# 情報を確認する時刻の設定 | |
# デフォルトは一週間前 | |
todaytime = datetime.datetime.utcnow() | |
endtime = todaytime - datetime.timedelta(days=7) | |
starttime = todaytime - datetime.timedelta(days=8) | |
todaytime = todaytime.strftime("%Y%m%d%H%M%S") | |
endtime = endtime.strftime("%Y%m%d%H%M%S") | |
starttime = starttime.strftime("%Y%m%d%H%M%S") | |
print("-------from_arXiv_to_Gmail.py-------") | |
print("ただいまの日時:" + todaytime) | |
print("出力日時:" + starttime + " TO " + endtime) | |
# arXivから情報を取得する(result_list) | |
result_list = arxiv.Search( | |
query = QUERY_cat + " AND submittedDate:[" + starttime + " TO " + endtime + "]", | |
# max_results = 1, | |
sort_by = arxiv.SortCriterion.SubmittedDate | |
) | |
# 情報を出力したカウント(count) | |
count = 1 | |
# 「出力開始」のログを出力 | |
print("-------出力開始-------") | |
size = len([result for result in result_list.get()]) | |
# result_listでループ | |
for result in result_list.get(): | |
# 細かな情報を取得 | |
title = result.title | |
authors = result.authors | |
date = result.published | |
category = result.categories | |
journalref = result.journal_ref | |
abst = result.summary | |
comment = result.comment | |
absurl = result.entry_id | |
pdfurl = result.pdf_url | |
doiurl = result.doi | |
# タイトルの日本語訳を取得 | |
title_jpn = translator.translate(title, src='en' ,dest='ja').text | |
time.sleep(1) | |
# 著者を整形 | |
new_authors = [] | |
for author in authors: | |
new_authors.append(author.name) | |
new_authors = "; ".join(new_authors) | |
# ジャーナル情報を整形 | |
if journalref == None: | |
journalref = "No Journal Reference." | |
# カテゴリーを整形 | |
new_category = ", ".join(category) | |
# 概要の日本語訳を取得 | |
abst = abst.replace("\n"," ") | |
abst_jpn = translator.translate(abst, src='en' ,dest='ja').text | |
time.sleep(1) | |
# コメントの日本語訳を取得 | |
if comment == None: | |
comment = "No comment." | |
comment_jpn = translator.translate(comment, src='en' ,dest='ja').text | |
time.sleep(1) | |
# doiurlを整形 | |
if doiurl == None: | |
doiurl = "No doi link." | |
else: | |
doiurl = "https://doi.org/" + doiurl | |
# ログを出力 | |
print() | |
print("-------" + str(count) + "/" + str(size) +"ページ目-------") | |
print("Title: {}".format(title)) | |
print("タイトル: {}".format(title_jpn)) | |
try: | |
print("Authors: {}".format(new_authors)) | |
except Exception as e: | |
print("Authors: " + str(e)) | |
print("Published(UTC): " + str(date)) | |
print("Journal Reference: " + journalref) | |
print("Categories: " + new_category) | |
print("") | |
print("Abstract: ") | |
try: | |
print("{}".format(abst)) | |
except Exception as e: | |
print("{}".format(e)) | |
print("") | |
print("概要: ") | |
try: | |
print("{}".format(abst_jpn)) | |
except Exception as e: | |
print("{}".format(e)) | |
print("") | |
print("Comment: ") | |
try: | |
print("{}".format(comment)) | |
except Exception as e: | |
print("{}".format(e)) | |
print("") | |
print("コメント: ") | |
try: | |
print("{}".format(comment_jpn)) | |
except Exception as e: | |
print("{}".format(e)) | |
print("") | |
print("URL: {}".format(absurl)) | |
print("PDFのURL: {}".format(pdfurl)) | |
print("doiのURL: {}".format(doiurl)) | |
# WebhookへPost | |
if doiurl == "No doi link.": | |
message = "\n".join(["Title: " + title + "<br>タイトル: " + title_jpn + "<br>Authors: " + new_authors + "<br>Published(UTC): " + str(date) + "<br>Journal Reference: " + journalref + "<br>Categories: " + new_category + "<br><br>Abstract: <br>" + abst + "<br><br>概要: <br>" + abst_jpn + "<br><br>Comment: <br>" + comment + "<br><br>コメント: <br>" + comment_jpn + "<br><br>URL: <a href=\"" + absurl + "\">" + absurl + "</a>" + "<br>PDFのURL: <a href=\"" + pdfurl + "\">" + pdfurl + "</a>" + "<br>doiのURL: " + doiurl]) | |
else: | |
message = "\n".join(["Title: " + title + "<br>タイトル: " + title_jpn + "<br>Authors: " + new_authors + "<br>Published(UTC): " + str(date) + "<br>Journal Reference: " + journalref + "<br>Categories: " + new_category + "<br><br>Abstract: <br>" + abst + "<br><br>概要: <br>" + abst_jpn + "<br><br>Comment: <br>" + comment + "<br><br>コメント: <br>" + comment_jpn + "<br><br>URL: <a href=\"" + absurl + "\">" + absurl + "</a>" + "<br>PDFのURL: <a href=\"" + pdfurl + "\">" + pdfurl + "</a>" + "<br>doiのURL: <a href=\"" + doiurl + "\">" + doiurl + "</a>"]) | |
title = "arXiv投稿通知(" + str(count) + "/" + str(size) + "): " + title | |
response = requests.post(API_URL, data={"value1": message, "value2": title, "value3": pdfurl}) | |
# countを+1 | |
count += 1 | |
# 5秒間休止 | |
time.sleep(5) | |
# 「出力完了」のログを出力 | |
print() | |
print("-------出力完了-------") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment