From c14ea22d5154d38e4c605a65457eacc1bda1404e Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 10 Nov 2020 20:06:20 -0800 Subject: [PATCH] Use requests.Session. --- droidz.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/droidz.py b/droidz.py index 11f7648..e7aa2b9 100644 --- a/droidz.py +++ b/droidz.py @@ -51,13 +51,19 @@ SQL_COLUMNS = sqlhelpers.extract_table_column_map(DB_INIT) sql = sqlite3.connect('sticks.db') 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 = { 'User-Agent': USERAGENT } +session = requests.Session() +session.headers.update(HEADERS) + DOWNLOAD_RATELIMITER = ratelimiter.Ratelimiter(allowance=1, period=5) WINRAR = winwhich.which('winrar') @@ -130,7 +136,7 @@ def insert_sticks(datas, commit=True): ################################################################################ def request(url): print(url) - response = requests.get(url, headers=HEADERS) + response = session.get(url) response.raise_for_status() return response