From 42f3eecc8ebcae73088fc2f02f1ede2d65c36228 Mon Sep 17 00:00:00 2001 From: Michael Yick Date: Mon, 27 Feb 2023 16:56:31 -0600 Subject: improved back off --- main.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index be64396..10efd18 100755 --- a/main.py +++ b/main.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 import requests +from requests.adapters import HTTPAdapter +from urllib3.util.retry import Retry import bs4 import time import feedgenerator -import json from datetime import datetime, timedelta from fastapi import FastAPI, Response @@ -21,6 +22,15 @@ async def root(): for day in range(0,7): rawDate = datetime.today() - timedelta(days = day) date = rawDate.strftime('%Y-%m-%d') + + session = requests.Session() + retry = Retry(connect=3, backoff_factor=0.5) + adapter = HTTPAdapter(max_retries=retry) + session.mount('http://', adapter) + session.mount('https://', adapter) + + session.get("https://dilbert.com/strip/" + date) + tries = 25 for i in range(tries): search = requests.get("https://dilbert.com/strip/" + date) -- cgit v1.2.3