-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive.py
92 lines (54 loc) · 1.69 KB
/
archive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import sqlite3
import xlwt
import pickle
def save_variable(v, filename):
f = open(filename, 'wb')
pickle.dump(v, f)
f.close()
return filename
def load_variavle(filename):
f = open(filename, 'rb')
r = pickle.load(f)
f.close()
return r
dbpath = "pubmedsql"
conn = sqlite3.connect(dbpath)
cursor = conn.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
cursor.fetchall()
cursor.execute("SELECT * FROM pubmed20230418145958")
cursor.fetchall()
conn.commit()
cursor.close()
sys.path.append("/Users/hanxiangming/Library/CloudStorage/Dropbox/documents/Code/my_functions.py")
from my_functions import *
traverse(html)
save_variable(html, "html")
html = load_variavle("html")
import re
import pandas as pd
# 读取文件并将数据整理成列表
with open('J_Medline.txt', 'r') as f:
data = f.read()
records = re.split('-{50,}\n', data.strip())
records = [r.strip().split('\n') for r in records]
# 将数据转换为DataFrame
columns = ['JrId', 'JournalTitle', 'MedAbbr', 'ISSN (Print)', 'ISSN (Online)', 'IsoAbbr', 'NlmId']
df = pd.DataFrame(records, columns=columns)
# 删除空格
df = df.apply(lambda x: x.str.strip())
df = df.apply(lambda x: x.str.replace(r'^.*?:\s*', '').str.strip())
df = df.iloc[1:]
print(df)
# 保存为csv文件
df.to_csv('J_Medline.csv', index=False)
# 开始测试scihub.py
from scihub import SciHub
sh = SciHub()
# 通过doi下载
# exactly the same thing as fetch except downloads the articles to disk
# if no path given, a unique name will be used as the file name
# 直接下载是可行的
#%%
result = sh.download('https://doi.or86/s13045-021-01052-y', path='./document/pub/test.pdf')
print("sss")