Skip to content

Commit 3205d24

Browse files
committed
Bugfix: fix the pubmed advance query support
1 parent 84644c7 commit 3205d24

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

main.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from utils.ExcelHelper import ExcelHelper
1111
from utils.PDFHelper import PDFHelper
1212
from utils.WebHelper import WebHelper
13+
from utils.LogHelper import print_error
1314
from config import ProjectInfo, projConfig
1415

1516
feedbacktime = projConfig.feedbacktime
@@ -61,7 +62,7 @@ def printSpliter(length=25):
6162
help='add --directory or -D specify the save path of pdf file'
6263
'For example, -D ./output. Default path is ./document/pub'
6364
'you can overrider the default path in config.py',
64-
default='./document/pub')
65+
default=None)
6566

6667
parser.add_argument("-p", "--pmid", type=str, metavar='',
6768

@@ -88,12 +89,18 @@ def printSpliter(length=25):
8889
# the default pdf saving directory path is from config.py which is './document/pub'
8990
if args.directory is not None:
9091
projConfig.pdfSavePath = args.directory
92+
else:
93+
if projConfig.pdfSavePath is None:
94+
print_error("Error" "Neither directory of cli nor pdfSavePath in config.py is None.")
95+
print_error("Please check your config.py and cli parameter." "The program will exit.")
96+
sys.exit()
9197

9298
if args.keyword.isspace() or args.keyword.isnumeric():
9399
print("pubmedsoso search keyword error\n")
100+
print_error("the program will exit.")
94101
sleep(feedbacktime)
95-
96-
102+
103+
######################################################################################################
97104

98105
print(f"Current commandline parameters: {args.__dict__}\n")
99106
print(
@@ -116,6 +123,8 @@ def printSpliter(length=25):
116123
sleep(feedbacktime * 0.5)
117124
sys.exit()
118125

126+
######################################################################################################
127+
119128
printSpliter()
120129
print("程序已运行,开始检查数据储存目录\n")
121130
printSpliter()

utils/WebHelper.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ class WebHelper:
2121
session = requests.Session()
2222

2323
@classmethod
24-
def createParamDcit(cls, keyword, year: Union[int, None] = None):
25-
26-
if " " in keyword:
27-
keyword = keyword.replace(" ", "%20")
24+
def createParamDcit(cls, keyword:str, year: Union[int, None] = None):
25+
2826
search_keywords_dict = {}
2927
search_keywords_dict['term'] = keyword.strip()
3028

@@ -35,9 +33,9 @@ def createParamDcit(cls, keyword, year: Union[int, None] = None):
3533
search_keywords_dict['size'] = 50
3634

3735
return search_keywords_dict
38-
39-
@staticmethod
40-
def encodeParam(param: dict) -> str:
36+
37+
@classmethod
38+
def encodeParam(cls, param: dict) -> str:
4139
return urllib.parse.urlencode(param)
4240

4341
@staticmethod

0 commit comments

Comments
 (0)