add cookie extractor only supports firefox for now

This commit is contained in:
ccppi 2024-08-22 10:04:39 +02:00
parent 3dcba94b95
commit ad969abfe1

View File

@ -3,10 +3,18 @@ import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from enum import Enum from enum import Enum
import re import re
import shutil
from dateconverter import * from dateconverter import *
from datetime import datetime from datetime import datetime
import os
import sqlite3
DEBUG = True DEBUG = True
number = ['0','1','2','3','4','5','6','7','8','9'] 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"
def log(*s): def log(*s):
if DEBUG: if DEBUG:
print(s) print(s)
@ -208,8 +216,33 @@ def indeedExtractDays(datestr):
cleannumstr+=a cleannumstr+=a
elif a not in number and foundchar == True: elif a not in number and foundchar == True:
break break
if cleannumstr != '':
cleannumint = int(cleannumstr) cleannumint = int(cleannumstr)
today = int(datetime.utcnow().timestamp()) today = int(datetime.utcnow().timestamp())
cleandate = today - cleannumint * 60 * 60 * 7 * 4 cleandate = today - cleannumint * 60 * 60 * 7 * 4
#print("int:",cleannumint,"today:",today,"cleandate:",datetime.fromtimestamp(cleandate).strftime('%Y-%m-%d')) #print("int:",cleannumint,"today:",today,"cleandate:",datetime.fromtimestamp(cleandate).strftime('%Y-%m-%d'))
return datetime.fromtimestamp(cleandate).strftime('%Y-%m-%d') return datetime.fromtimestamp(cleandate).strftime('%Y-%m-%d')
return "NOTFound"
def getCookieFromBrowser(url):
#workaround for loked database
shutil.copyfile(cookiePath,tmpPath)
cookie = ''
rows = [0]
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,('%'+'indeed'+'%',))
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)
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%'