add some string operation functions

This commit is contained in:
ccppi 2024-08-22 10:52:45 +02:00
parent ad969abfe1
commit 1a39285ed7

View File

@ -223,7 +223,7 @@ 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 getCookieFromBrowser(url):
def getCookiesFromBrowser(url):
#workaround for loked database
shutil.copyfile(cookiePath,tmpPath)
cookie = ''
@ -233,7 +233,7 @@ def getCookieFromBrowser(url):
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,('%'+'indeed'+'%',))
cursor.execute(cmd_read_cookies,('%'+url+'%',))
while len(rows)!=0:
rows = cursor.fetchmany(25)
for row in rows:
@ -246,3 +246,44 @@ def getCookieFromBrowser(url):
#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)
print("url cut",urlCut)
posDot = skipAfterChar(urlCut,'.')
urlCut = dropBeforePos(urlCut,posDot)
print("url after cut dot:",urlCut)
posDot = skipAfterChar(urlCut,'.')
urlCut = dropAfterPos(urlCut,posDot)
print("url after cut dot:",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