Use requests.Session.
This commit is contained in:
parent
29c80b2662
commit
c14ea22d51
1 changed files with 9 additions and 3 deletions
12
droidz.py
12
droidz.py
|
@ -51,13 +51,19 @@ SQL_COLUMNS = sqlhelpers.extract_table_column_map(DB_INIT)
|
||||||
sql = sqlite3.connect('sticks.db')
|
sql = sqlite3.connect('sticks.db')
|
||||||
sql.executescript(DB_INIT)
|
sql.executescript(DB_INIT)
|
||||||
|
|
||||||
USERAGENT = '''Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
|
|
||||||
Chrome/79.0.3945.130 Safari/537.36'''.replace('\n', ' ').strip()
|
USERAGENT = '''
|
||||||
|
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
|
||||||
|
Chrome/79.0.3945.130 Safari/537.36
|
||||||
|
'''.replace('\n', ' ').strip()
|
||||||
|
|
||||||
HEADERS = {
|
HEADERS = {
|
||||||
'User-Agent': USERAGENT
|
'User-Agent': USERAGENT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session = requests.Session()
|
||||||
|
session.headers.update(HEADERS)
|
||||||
|
|
||||||
DOWNLOAD_RATELIMITER = ratelimiter.Ratelimiter(allowance=1, period=5)
|
DOWNLOAD_RATELIMITER = ratelimiter.Ratelimiter(allowance=1, period=5)
|
||||||
|
|
||||||
WINRAR = winwhich.which('winrar')
|
WINRAR = winwhich.which('winrar')
|
||||||
|
@ -130,7 +136,7 @@ def insert_sticks(datas, commit=True):
|
||||||
################################################################################
|
################################################################################
|
||||||
def request(url):
|
def request(url):
|
||||||
print(url)
|
print(url)
|
||||||
response = requests.get(url, headers=HEADERS)
|
response = session.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue