Skip to content

Commit

Permalink
fixed windows path problem
Browse files Browse the repository at this point in the history
  • Loading branch information
JinjieNi committed Nov 4, 2023
1 parent ea147f0 commit 47afd5e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
4 changes: 1 addition & 3 deletions build/lib/easy_literature/arxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ def get_info_by_title(self, title, field='ti'):
arxiv_info.set_proxy_handler(proxy="127.0.1:1123")

bib_arxiv = arxiv_info.get_info_by_arxivid(arxivId)
# bib_title = arxiv_info.get_info_by_title(title)

print(bib_arxiv)
print("\n")
# print(bib_title)
print("\n")
15 changes: 11 additions & 4 deletions build/lib/easy_literature/downloads.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import re
import os
import os
import platform

from .arxiv import arxivInfo
from .crossref import crossrefInfo
Expand Down Expand Up @@ -107,11 +108,17 @@ def get_paper_pdf_from_paperid(paper_id, path, proxy=None, direct_url=None):
else:
content = pdf_downloader.get_pdf_from_sci_hub(paper_id)
try:
if not os.path.exists(path.rsplit("/", 1)[0]):
os.makedirs(path.rsplit("/", 1)[0])
system = platform.system()
if system == 'Windows':
path = path.replace("/", "\\")
pdf_dir = path.rsplit("\\", 1)[0]
else:
pdf_dir = path.rsplit("/", 1)[0]
if not os.path.exists(pdf_dir):
os.makedirs(pdf_dir)
pdf_downloader._save(content['pdf'], path)
except:
pass
pass



2 changes: 0 additions & 2 deletions build/lib/easy_literature/easyliter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def file_update(input_path, output_path, proxy, paper_recognizer, gproxy_mode):

replace_dict = get_bib_and_pdf(input_path, output_path,
proxy, paper_recognizer, gproxy_mode)
# logger.info(replace_dict)

if replace_dict:
note_modified(paper_recognizer, input_path, **replace_dict)
Expand Down Expand Up @@ -133,7 +132,6 @@ def main():

matched_numb += len(matched_pdfs)

# os.path.relpath(pdf_path, note_file).split('/',1)[-1]
replace_paths_dict = {}
for matched in matched_pdfs:
replaced_str = os.path.relpath(pdf_paths_dict[matched], md_file).split('/',1)[-1]
Expand Down
13 changes: 7 additions & 6 deletions build/lib/easy_literature/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,17 @@ def get_update_content(m, note_file, pdfs_path, proxy, gproxy_mode):
pdf_name = re.sub(r'[\n\t\r]', '', pdf_name)
# remove multiple blank spaces
pdf_name = re.sub(r' +', ' ', pdf_name)
pdf_name = re.sub(r'[.]', '', pdf_name)

pdf_name = '_'.join(pdf_name.split(' ')) + '.pdf'

# remove the special characters in the pdf name: / \ : * ? " < > |
pdf_name = re.sub(r'[\\/:*?"<>|]', '', pdf_name)
pdf_path = os.path.join(pdfs_path, pdf_name)

logger.info(f"The pdf path to be saved: {pdf_path}")
if pdf:
id_type = classify(literature_id)
# logger.info(f"the literid: {literature_id}; classified as: {id_type}")
if id_type == "title":
for pattern_str in [r'10\.(?!1101)[0-9]{4}/', r'10\.1101/', r'[0-9]{2}[0-1][0-9]\.[0-9]{3,}', r'.*/[0-9]{2}[0-1][0-9]{4}']:
res = re.search(pattern_str, bib['url']) # search for the arxiv id in the url
Expand All @@ -151,17 +152,17 @@ def get_update_content(m, note_file, pdfs_path, proxy, gproxy_mode):
get_paper_pdf_from_paperid(literature_id, pdf_path, direct_url=bib['pdf_link'], proxy=proxy)
if not os.path.exists(pdf_path):
get_paper_pdf_from_paperid(literature_id, pdf_path, proxy=proxy)
# logger.info(bib['journal'])
if os.path.exists(pdf_path):
replaced_literature = "- **{}**. {} et.al. **{}**, **{}**, **Number of Citations: **{}, ([pdf]({}))([link]({})).".format(
bib['title'], bib["author"].split(" and ")[0], bib['journal'],
bib['year'], bib['cited_count'], os.path.relpath(pdf_path, note_file).split('/',1)[-1],
bib['url'])
else:
replaced_literature = "- **{}**. {} et.al. **{}**, **{}**, **Number of Citations: **{}, ([link]({})).".format(
bib['title'], bib["author"].split(" and ")[0], bib['journal'],
bib['year'], bib['cited_count'], f'{pdfs_path}/your_pdf_name.pdf', bib['url']
)
logger.info("Can not find a downloading source for literature id {}. You may need to manually download this paper, a template has been generated in the markdown file. Put the pdf file in the folder you specified just now and add its name in the '(pdf)' of your markdown entry.".format(literature_id))
replaced_literature = "- **{}**. {} et.al. **{}**, **{}**, **Number of Citations: **{}, ([pdf]({}))([link]({})).".format(
bib['title'], bib["author"].split(" and ")[0], bib['journal'],
bib['year'], bib['cited_count'], f'{pdfs_path}/your_pdf_name.pdf', bib['url']
)
replace_dict[literature] = replaced_literature
except:

Expand Down
3 changes: 2 additions & 1 deletion easy_literature/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ def get_paper_pdf_from_paperid(paper_id, path, proxy=None, direct_url=None):
try:
system = platform.system()
if system == 'Windows':
path = path.replace("/", "\\")
pdf_dir = path.rsplit("\\", 1)[0]
else:
pdf_dir = path.rsplit("/", 1)[0]
if not os.path.exists(pdf_dir):
os.makedirs(pdf_dir)
pdf_downloader._save(content['pdf'], path)
except:
pass
pass



2 changes: 1 addition & 1 deletion easyliter.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: easyliter
Version: 1.0.3
Version: 1.0.5
Summary: EasyLiterature is a opensourced, Python-based command line tool for automatic literature management. Simply list the paper titles (or ids) you want to read in a markdown file and it will automatically collect and refine its information in the markdown file, download the pdf to your local machine, and link the pdf to your paper in the markdown file. You can forever keep your notes within the pdfs and mds on your local machine or cloud driver.
Home-page: https://github.com/Psycoy/EasyLiterature
Author: Oliver
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="easyliter",
version="1.0.3",
version="1.0.5",
description="EasyLiterature is a opensourced, Python-based command line tool for automatic literature management. Simply list the paper titles (or ids) you want to read in a markdown file and it will automatically collect and refine its information in the markdown file, download the pdf to your local machine, and link the pdf to your paper in the markdown file. You can forever keep your notes within the pdfs and mds on your local machine or cloud driver.",
long_description=README_MD,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 47afd5e

Please sign in to comment.