diff --git a/lib/helpers.py b/lib/helpers.py index 8492f36..fdc3acf 100644 --- a/lib/helpers.py +++ b/lib/helpers.py @@ -9,15 +9,13 @@ from datetime import datetime import os import sqlite3 import webbrowser -from time import sleep +import mozilla DEBUG = True number = ['0','1','2','3','4','5','6','7','8','9'] -homePath = os.path.expanduser('~') -cookiePath = homePath + "/.mozilla/firefox/imibizoh.default/cookies.sqlite" -tmpPath = "/tmp/cookies.sqlite" -DBFILE = "../db/sqlite3.db" -winFirefoxPath = f"""C:\Program Files\Mozilla Firefox\firefox.exe""" + + + def log(*s): if DEBUG: print(s) @@ -226,77 +224,4 @@ def indeedExtractDays(datestr): #print("int:",cleannumint,"today:",today,"cleandate:",datetime.fromtimestamp(cleandate).strftime('%Y-%m-%d')) return datetime.fromtimestamp(cleandate).strftime('%Y-%m-%d') return "NOTFound" -def getCookiesFromBrowser(url): - #workaround for loked database - tries=0 - cookie = '' - rows = [0] - while(cookie == '' and tries < 2): - tries+=1; - shutil.copyfile(cookiePath,tmpPath) - with sqlite3.connect(tmpPath) as connection: - cmd_read_cookies = f"""SELECT name,value FROM moz_cookies WHERE host like ?;""" - print(cmd_read_cookies) - cursor = connection.cursor() - cursor.execute(cmd_read_cookies,(urlToDomain(url),)) - while len(rows)!=0: - rows = cursor.fetchmany(25) - for row in rows: - print("row:",row) - cookie = cookie + row[0] + '=' + row[1] - cookie += ";" - print("Cookies:",cookie) - if cookie == '': - if os.name == 'posix': - webbrowser.register("firefox",None,webbrowser.BackgroundBrowser("firefox")) - webbrowser.get('firefox').open(url) - elif os.name == 'nt': - webbrowser.register("firefox",None,webbrowser.BackgroundBrowser(winFirefoxPath)) - webbrowser.get('firefox').open(url) - sleep(1) - return cookie -#access cookies from firefox: -#copy (because locked): cp .mozilla/firefox/imibizoh.default/cookies.sqlite cookies.sqlite -#Select value from moz_cookies where host like '%indeed%' -def urlToDomain(url): - pos = patternSearch(url,"https://") - urlCut = dropBeforePos(url,pos) - posDot = skipAfterChar(urlCut,'.') - 1 - urlCut = dropBeforePos(urlCut,posDot) - posDot = skipAfterChar(urlCut,'/') - urlCut = dropAfterPos(urlCut,posDot) - print("url after cut dot:",urlCut) - return urlCut - -def patternSearch(url,pattern): - x = 0 - for a,i in enumerate(url): - print("i:",i) - if i == pattern[x]: - if x