restructing
This commit is contained in:
@@ -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<len(pattern)-1:
|
||||
x = x + 1
|
||||
elif x==len(pattern)-1:
|
||||
print("FULL PATTERN FOUND at pos :",a)
|
||||
break
|
||||
else:
|
||||
x = 0
|
||||
return a
|
||||
def skipAfterChar(aString,char):
|
||||
for a,i in enumerate(aString):
|
||||
if i == char:
|
||||
break
|
||||
return a
|
||||
def dropBeforePos(aString,pos):
|
||||
aString2=''
|
||||
pos+=1
|
||||
if pos < len(aString):
|
||||
for i in range(pos,len(aString)):
|
||||
aString2 += aString[i]
|
||||
return aString2
|
||||
def dropAfterPos(aString,pos):
|
||||
aString2=''
|
||||
if pos < len(aString):
|
||||
for i in range(0,pos):
|
||||
aString2 += aString[i]
|
||||
return aString2
|
||||
|
||||
Reference in New Issue
Block a user