From 317ecee4d81a464021e36fd8b7e06b15478973ea Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Fri, 15 Sep 2023 15:35:30 +0800 Subject: [PATCH] Update v1.1.4 --- VERSION | 2 +- arxiv_dl/arxiv_dl.py | 2 ++ arxiv_dl/bin/arxiv-dl | 3 +++ arxiv_dl/bin/getpaper | 3 +++ arxiv_dl/bin/paper | 3 +++ arxiv_dl/helpers.py | 15 +++++++++------ arxiv_dl/updater.py | 39 +++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 8 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 arxiv_dl/updater.py diff --git a/VERSION b/VERSION index 9c1218c..1b87bcd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.3 \ No newline at end of file +1.1.4 \ No newline at end of file diff --git a/arxiv_dl/arxiv_dl.py b/arxiv_dl/arxiv_dl.py index 4d0e479..307ed5d 100644 --- a/arxiv_dl/arxiv_dl.py +++ b/arxiv_dl/arxiv_dl.py @@ -22,6 +22,7 @@ scrape_metadata_nips, scrape_metadata_openreview, ) +from .updater import check_update def main( @@ -38,6 +39,7 @@ def main( Download paper and extract paper metadata """ + ### Get Target Download Directory try: if download_dir is None: diff --git a/arxiv_dl/bin/arxiv-dl b/arxiv_dl/bin/arxiv-dl index 58fcef6..2dda4c5 100755 --- a/arxiv_dl/bin/arxiv-dl +++ b/arxiv_dl/bin/arxiv-dl @@ -2,6 +2,7 @@ import argparse from arxiv_dl.arxiv_dl import main +from arxiv_dl.updater import check_update parser = argparse.ArgumentParser() parser.add_argument( @@ -41,6 +42,8 @@ args = parser.parse_args() urls = args.urls +check_update() + for i, url in enumerate(urls): print(f"[{i+1}/{len(urls)}] >>> {url}") try: diff --git a/arxiv_dl/bin/getpaper b/arxiv_dl/bin/getpaper index 58fcef6..2dda4c5 100755 --- a/arxiv_dl/bin/getpaper +++ b/arxiv_dl/bin/getpaper @@ -2,6 +2,7 @@ import argparse from arxiv_dl.arxiv_dl import main +from arxiv_dl.updater import check_update parser = argparse.ArgumentParser() parser.add_argument( @@ -41,6 +42,8 @@ args = parser.parse_args() urls = args.urls +check_update() + for i, url in enumerate(urls): print(f"[{i+1}/{len(urls)}] >>> {url}") try: diff --git a/arxiv_dl/bin/paper b/arxiv_dl/bin/paper index 58fcef6..2dda4c5 100755 --- a/arxiv_dl/bin/paper +++ b/arxiv_dl/bin/paper @@ -2,6 +2,7 @@ import argparse from arxiv_dl.arxiv_dl import main +from arxiv_dl.updater import check_update parser = argparse.ArgumentParser() parser.add_argument( @@ -41,6 +42,8 @@ args = parser.parse_args() urls = args.urls +check_update() + for i, url in enumerate(urls): print(f"[{i+1}/{len(urls)}] >>> {url}") try: diff --git a/arxiv_dl/helpers.py b/arxiv_dl/helpers.py index d077dac..f0eddf5 100644 --- a/arxiv_dl/helpers.py +++ b/arxiv_dl/helpers.py @@ -1,7 +1,6 @@ import json import logging import os -import pypdf import re import shlex import string @@ -9,6 +8,8 @@ from pathlib import Path from typing import Union +import pypdf + from .dl_utils import download from .logger import logger from .models import PaperData @@ -196,11 +197,13 @@ def add_pdf_metadata(paper_data: PaperData, download_path: Path): writer.add_metadata(metadata) # Add the new metadata - writer.add_metadata({ - "/Author": ", ".join(paper_data.authors), - "/Title": paper_data.title, - "/Subject": paper_data.abstract, - }) + writer.add_metadata( + { + "/Author": ", ".join(paper_data.authors), + "/Title": paper_data.title, + "/Subject": paper_data.abstract, + } + ) # Save the new PDF to a file with open(download_path, "wb") as f: diff --git a/arxiv_dl/updater.py b/arxiv_dl/updater.py new file mode 100644 index 0000000..1ccf806 --- /dev/null +++ b/arxiv_dl/updater.py @@ -0,0 +1,39 @@ +import json + +import pkg_resources +import requests + + +def check_latest_version(): + """Check the latest version of arxiv-dl on PyPI.""" + pypi_url = "https://pypi.org/pypi/arxiv-dl/json" + response = requests.get(pypi_url) + if response.status_code == 200: + pypi_data = response.text + pypi_data = json.loads(pypi_data) + latest_version = pypi_data.get("info", {}).get("version", "") + else: + latest_version = "" + return latest_version + + +def check_current_version(): + """Check the current version of arxiv-dl.""" + current_version = pkg_resources.get_distribution("arxiv-dl").version + return current_version + + +def check_update(): + """Remind user to update arxiv-dl if there is a new version.""" + latest_version = check_latest_version() + current_version = check_current_version() + print(f"[arxiv-dl] (version: {current_version})") + + if latest_version and latest_version != current_version: + print( + f"[arxiv-dl] latest version available: {latest_version}. You may update by running: pip install --upgrade arxiv-dl" + ) + + +if __name__ == "__main__": + check_update() diff --git a/setup.py b/setup.py index d912a4d..bc0180c 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ MAJOR = 1 MINOR = 1 -MICRO = 3 +MICRO = 4 VERSION = "%d.%d.%d" % (MAJOR, MINOR, MICRO)