implement cancel button to cancel login profedure and continue with the

next entry
This commit is contained in:
ccppi 2024-08-08 11:58:50 +02:00
parent 83e0d81ebe
commit e0e54adb5d
5 changed files with 27 additions and 26 deletions

View File

@ -18,7 +18,7 @@ class Entry:
if self.gui:
worker.messageContent = self.scrapurl
worker.dialog_closed=False
worker.pwprompt.emit() #signal to mainthread
worker.pwprompt.emit() #signal to mainthread run showDialog and wait for close
while not worker.dialog_closed:
time.sleep(1)
pass

View File

@ -91,8 +91,10 @@ def writedb(jobs):
log(hash1);
if(cursor.execute("SELECT * FROM jobs WHERE hash = ?",(hash1,)).fetchone() != None):
log("Hash already exist")
elif(cursor.execute("SELECT * FROM jobs where link = ?",(job.link,)).fetchone() != None):
log("link already exist")
else:
print("NEW_ENTRY")
log("NEW_ENTRY")
cursor.execute("INSERT INTO jobs (star,tag,title,company,location,link,pubdate,hash,viewed) VALUES (?,?,?,?,?,?,?,?,?)",(job.starred,job.tag,job.title,job.company,job.location,job.link,job.date,hash1,0))
def viewedEntry(hash1):

View File

@ -9,6 +9,11 @@ import sys
import db as db
from qsqlmod import SqlQueryModel_editable
DEBUG = True
def log(*s):
if DEBUG:
print(s)
DBFILE = "../db/sqlite3.db"
Cantons = ["AG","ZH","BE","SG","SO"]
@ -22,12 +27,9 @@ class ColorDelegate(QStyledItemDelegate):
print("initialice overload init of ColorDelegate")
self.main = main
def initStyleOption(self,option,index):
#we have to rewrite this because it depends on viewport but it should depend on the model
super().initStyleOption(option,index)
data = index.data()
column = index.column()
#flag_viewed = self.main.model.index(index.row(),8).data()
#flag_starred = self.main.model.index(index.row(),0).data()
flag_viewed = self.main.sel_model.model().index(index.row(),8).data()
try:
flag_starred = int(self.main.sel_model.model().index(index.row(),0).data())
@ -35,11 +37,10 @@ class ColorDelegate(QStyledItemDelegate):
print("probably empty string asign zero")
flag_starred = 0
print("index:",index)
print("column ",column)
print("data:", flag_starred)
#print("index:",index)
#print("column ",column)
#print("data:", flag_starred)
if flag_starred == 1:
print("Starred!!!!!")
option.backgroundBrush = QtGui.QColor("red")
elif flag_viewed != 1:
option.backgroundBrush = QtGui.QColor("green")
@ -89,6 +90,7 @@ class Worker(QObject):
pw = Signal(str)
finished = Signal()
dialog_closed = True
dialog_rejected = False
password = ['empty']
def run(self):
@ -123,13 +125,6 @@ class MainWindow(QMainWindow):
editables = {0 : ("UPDATE jobs SET star = '{}' WHERE hash = '{}'",7)}
self.model = SqlQueryModel_editable(editables)
#self.model.setTable("jobs")
#self.model.setEditStrategy(QSqlTableModel.OnFieldChange)
#self.model.select()
#self.proxymodel2 = QSortFilterProxyModel(self)
#self.proxymodel2.setSourceModel(self.model)
#self.proxymodel2.setTable("jobs")
self.view = QTableView()
self.view.setModel(self.model)
@ -211,12 +206,13 @@ class MainWindow(QMainWindow):
w = PWPrompt()
w.set_MSG(self.worker.messageContent)
ret = w.exec()
if ret == QDialog.Rejected:
self.worker.dialog_rejected = True
log("[gui] qdialog.rejected set to TRUE")
self.pw = w.pw
self.worker.password = w.pw
print("showDialog,self.pw:",self.pw)
log("showDialog,self.pw:",self.pw)
self.worker.dialog_closed=True
if ret == QDialog.Rejected:
return 1
def showQueryWindow(self,checked):
if self.w is None:

View File

@ -45,7 +45,7 @@ def scrap_indeed_com(url,entry,session):
def scrap_jobs(url,entry,session):
jobs = []
log("in scrap jobs,url",url)
if(session == 0):
if(session == 0 or session == -1):
with requests.Session() as session:
page = session.get(url)
log(page)
@ -157,7 +157,7 @@ def next_url_jobagent(base_url,session,c):#depreacted will be removed in the fut
def scrap_jobagent(url,entry,session):
jobs = []
log("in scrap jobs,url",url)
if(session == 0):
if(session == 0 or session == -1):
with requests.Session() as session:
page = session.get(url)
log(page)

View File

@ -7,7 +7,7 @@ from login import *
from time import sleep
from db import *
DEBUG = False
DEBUG = True
def log(*s):
if DEBUG:
print(s)
@ -76,16 +76,19 @@ def login_loop(config_file,gui,worker):
ret_login = 0
session = 0
while (ret != 0):
worker.dialog_rejected = False
ret = entry2 = config.readConfig(config_file,gui,worker)
print(entry2)
if(ret != 0 and ret_login != 1):
if(entry2.loginurl != 'NONE'):
session = -1
while session == -1:
log("[pre while] worker.dialog_rejected = ",worker.dialog_rejected)
while (session == -1 and worker.dialog_rejected == False):
log("worker.dialog_rejected = ",worker.dialog_rejected)
session = login(entry2)
if session == -1:
ret_login = entry2.input_pw(gui,entry2.user,worker)
choose_scraper(entry2,session)
ret_login = entry2.input_pw(gui,entry2.user,worker)
if worker.dialog_rejected == False:
choose_scraper(entry2,session)
def runner(entry,session,scrap_func,next_url_func):
i=0