From 09ca7997f5ee0b19e6fc852052a0f7510c1168fd Mon Sep 17 00:00:00 2001 From: guanjihuan <34735497+guanjihuan@users.noreply.github.com> Date: Sat, 5 Jun 2021 14:58:58 +0800 Subject: [PATCH] version 0.0.12 --- GJH_source_code.py | 42 +++++++++++++++++++++++++++++++++++++++- PyPI/setup.cfg | 2 +- PyPI/src/gjh/__init__.py | 42 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/GJH_source_code.py b/GJH_source_code.py index 6607d8d..29042eb 100755 --- a/GJH_source_code.py +++ b/GJH_source_code.py @@ -942,4 +942,44 @@ def plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', s plt.savefig(filename+'.jpg', dpi=300) if show == 1: plt.show() - plt.close('all') \ No newline at end of file + plt.close('all') + + + + +# download + +def download_with_scihub(address=None, num=1): + from bs4 import BeautifulSoup + import re + import requests + import os + if num==1 and address!=None: + address_array = [address] + else: + address_array = [] + for i in range(num): + address = input('\nInput:') + address_array.append(address) + for address in address_array: + r = requests.post('https://sci-hub.st/', data={'request': address}) + print('\nResponse:', r) + print('Address:', r.url) + soup = BeautifulSoup(r.text, features='lxml') + pdf_URL = soup.iframe['src'] + if re.search(re.compile('^https:'), pdf_URL): + pass + else: + pdf_URL = 'https:'+pdf_URL + print('PDF address:', pdf_URL) + name = re.search(re.compile('fdp.*?/'),pdf_URL[::-1]).group()[::-1][1::] + print('PDF name:', name) + print('Directory:', os.getcwd()) + print('\nDownloading...') + r = requests.get(pdf_URL, stream=True) + with open(name, 'wb') as f: + for chunk in r.iter_content(chunk_size=32): + f.write(chunk) + print('Completed!\n') + if num != 1: + print('All completed!\n') \ No newline at end of file diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index 8636363..e48316d 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = gjh -version = 0.0.10 +version = 0.0.12 author = guanjihuan author_email = guanjihuan@163.com description = An open source python package diff --git a/PyPI/src/gjh/__init__.py b/PyPI/src/gjh/__init__.py index 821f974..357d97d 100644 --- a/PyPI/src/gjh/__init__.py +++ b/PyPI/src/gjh/__init__.py @@ -942,4 +942,44 @@ def plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', s plt.savefig(filename+'.jpg', dpi=300) if show == 1: plt.show() - plt.close('all') \ No newline at end of file + plt.close('all') + + + + +# download + +def download_with_scihub(address=None, num=1): + from bs4 import BeautifulSoup + import re + import requests + import os + if num==1 and address!=None: + address_array = [address] + else: + address_array = [] + for i in range(num): + address = input('\nInput:') + address_array.append(address) + for address in address_array: + r = requests.post('https://sci-hub.st/', data={'request': address}) + print('\nResponse:', r) + print('Address:', r.url) + soup = BeautifulSoup(r.text, features='lxml') + pdf_URL = soup.iframe['src'] + if re.search(re.compile('^https:'), pdf_URL): + pass + else: + pdf_URL = 'https:'+pdf_URL + print('PDF address:', pdf_URL) + name = re.search(re.compile('fdp.*?/'),pdf_URL[::-1]).group()[::-1][1::] + print('PDF name:', name) + print('Directory:', os.getcwd()) + print('\nDownloading...') + r = requests.get(pdf_URL, stream=True) + with open(name, 'wb') as f: + for chunk in r.iter_content(chunk_size=32): + f.write(chunk) + print('Completed!\n') + if num != 1: + print('All completed!\n') \ No newline at end of file