Skip to content

Commit

Permalink
fix bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorad committed Mar 12, 2022
1 parent e82798e commit 35af9ac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"endnotePath": "",
"scan": {
"scihubHost": "https://sci-hub.se",
"scihubHost": "https://sci-hub.ru",
"scanInterval": 1,
"numberOfProcess": 3
}
Expand Down
Binary file modified requirements.txt
Binary file not shown.
27 changes: 13 additions & 14 deletions src/CORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
logging.basicConfig(handlers=[logging.FileHandler(filename=os.path.join(logPath, logFilename),
encoding='utf-8', mode='a+')],
format='%(asctime)s %(filename)s : %(levelname)s %(message)s',
level=logging.DEBUG)
level=logging.ERROR)
logging.getLogger("pdfminer").setLevel(logging.ERROR)
logging.getLogger("urllib3").setLevel(logging.ERROR)

Expand Down Expand Up @@ -71,14 +71,9 @@ def saveConfig(config, path='config.json'):
CONFIG = loadConfig(configFilePath)

SCIHUB_HOST = [
'https://sci-hub.ee/',
'https://sci-hub.se/',
'https://sci-hub.mksa.top/',
'https://sci-hub.tf/',
'https://sci-hub.st/',
'https://sci.hubg.org/',
'https://sci-hub.hkvisa.net/',
'http://sci-hub.ren/'
'https://sci-hub.se',
'https://sci-hub.st',
'https://sci-hub.ru',
]

SCIHUB_HOST_KEY = 1
Expand All @@ -101,12 +96,12 @@ def getUnfinishTasks(self, firstTime=False):
if (firstTime):
self.__cleanHelperRecords()
refs = self.__searchReferencesWithDoiNoPdf()
insertRefs = [(r['id'], r['doi'], r['year'], r['title'], r['author']) for r in refs]
insertRefs = [(r['id'], r['doi'], r['year'], r['title'], r['author'], 'Waiting', '') for r in refs]
# push refs to helper database
conn = sqlite3.connect(self.helpDB)
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
cursor.executemany("INSERT INTO refs_helper(id,doi,year,title,author) VALUES(?,?,?,?,?)", insertRefs)
cursor.executemany("INSERT INTO refs_helper(id,doi,year,title,author,status,remark) VALUES(?,?,?,?,?,?,?)", insertRefs)
conn.commit()
# if (firstTime):
# cursor.execute("SELECT * FROM refs_helper WHERE status IS NULL OR status NOT LIKE '成功'")
Expand Down Expand Up @@ -286,7 +281,7 @@ def searchPdfBasedOnDoi(doi):
host = re.findall(r"(https?\:\/\/[\w.\-]+)", CONFIG['scan']['scihubHost'])
if (not len(host)):
logging.error('SCI-HUB host is error, host: %s' % (CONFIG['scan']['scihubHost']))
host = 'https://sci-hub.ee'
host = 'https://sci-hub.se'
else:
host = host[0]
r = requests.get(host + '/' + doi, headers={
Expand Down Expand Up @@ -322,6 +317,8 @@ def downloadPdf(url, savePath):
filename = re.findall("\/([\w\-_]+.pdf)", url)[0]
if ("Content-Disposition" in r.headers.keys() and r.headers["Content-Disposition"]):
filename = re.findall("filename=(.+)", r.headers["Content-Disposition"])[0]
if not os.path.exists(savePath):
os.makedirs(savePath)
fullFilenameWithPath = os.path.join(savePath, filename)
if (not os.path.exists(savePath)):
os.makedirs(savePath)
Expand Down Expand Up @@ -349,6 +346,7 @@ def run(self) -> None:
if self.taskQ.empty():
time.sleep(5)
continue
time.sleep(0.5)
ref = self.taskQ.get()
logging.debug('Got task %d, doi: %s, title: %s' % (ref['id'], ref['doi'], ref['title']))
self.endModel.updateRefStatusInHelperDb(ref, 'Searching', '')
Expand Down Expand Up @@ -400,10 +398,11 @@ def run(self) -> None:
# save to ref helper
for ref in refs:
self.taskQ.put(ref)
self.endnoteModel.updateRefStatusInHelperDb(ref, 'Waiting', '')
self.endnoteModel.updateRefStatusInHelperDb(ref, 'Queueing', 'Queueing for search.')
time.sleep(self.scanInterval)
for i in range(0, self.refHandlerNumber):
self.refHandlerProcesses[i].join()
self.refHandlerProcesses[i].terminate()
# self.refHandlerProcesses[i].join()
logging.debug('Handler %d stop.' % (i))
logging.info('Process RefMonitor stopped.')

Expand Down
15 changes: 12 additions & 3 deletions src/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging

logger = logging.getLogger("GUI")
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.ERROR)


class SystemTray():
Expand All @@ -29,7 +29,7 @@ def initUi(self):
statusItem = MenuItem('Task View', self.openTaskList)
RunningItem = MenuItem('Start', self.startService, checked=self.isRunning)
StopItem = MenuItem('Stop', self.stopService, checked=self.isStop)
self.icon = Icon("EndnoteHelper", Image.open('./res/icon.png'), "EndNoteHelper - v0.1.4", Menu(
self.icon = Icon("EndnoteHelper", Image.open('./res/icon.png'), "EndNoteHelper - v0.1.5", Menu(
statusItem, MenuItem('Service State', Menu(
RunningItem, StopItem
)), changeEndnoteDbItem, openConfigFileItem, aboutItem, quitItem
Expand Down Expand Up @@ -71,12 +71,15 @@ def stopService(self):
def openTaskList(self):
# if (hasattr(self, 'settingWindow') and self.settingWindow):
# self.settingWindow.destory()
logger.debug('Stopping')
if hasattr(self, 'taskWindow'):
return
logger.debug('open task list')
endnoteModel = EndNoteModel(os.path.dirname(self.config['endnotePath']),
os.path.basename(self.config['endnotePath']).replace('.enl', ''))
taskWindow = TaskListWindow(endnoteModel)
self.taskWindow = taskWindow
self.taskWindow.mainloop()
del self.taskWindow

def openSetting(self):
changeDbWindow = EndnoteDbPathSettingWindow(self.config)
Expand All @@ -97,8 +100,14 @@ def about(self):

def quit(self):
self.stopService()
if hasattr(self, 'taskWindow'):
self.taskWindow.quit()
self.refMonitor.stop()
# self.refMonitor.terminate()
self.refMonitor.join()
if (hasattr(self, 'icon') and self.icon):
self.icon.stop()
exit()


class EndnoteDbPathSettingWindow(tk.Tk):
Expand Down

0 comments on commit 35af9ac

Please sign in to comment.