events
Browse files- utils/events.py +21 -8
utils/events.py
CHANGED
|
@@ -1,14 +1,23 @@
|
|
| 1 |
import requests
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def get_burning_man_dates():
|
| 6 |
current_year = datetime.now().year
|
| 7 |
-
|
| 8 |
-
url = "https://burningman.org/
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
soup = BeautifulSoup(response.content, 'html.parser')
|
| 13 |
|
| 14 |
# Look for the heading that contains the year
|
|
@@ -23,8 +32,12 @@ def get_burning_man_dates():
|
|
| 23 |
result = f"Unable to find specific dates for Burning Man {current_year}."
|
| 24 |
else:
|
| 25 |
result = f"Unable to find information for Burning Man {current_year}."
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
return result
|
|
|
|
| 1 |
import requests
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
from datetime import datetime
|
| 4 |
+
import logging
|
| 5 |
+
|
| 6 |
+
logger = logging.getLogger(__name__)
|
| 7 |
|
| 8 |
def get_burning_man_dates():
|
| 9 |
current_year = datetime.now().year
|
| 10 |
+
logger.info(f"{current_year} is the current year")
|
| 11 |
+
url = "https://burningman.org/"
|
| 12 |
|
| 13 |
+
headers = {
|
| 14 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
response = requests.get(url, timeout=10, headers=headers)
|
| 19 |
+
response.raise_for_status() # This will raise an HTTPError for bad responses
|
| 20 |
+
|
| 21 |
soup = BeautifulSoup(response.content, 'html.parser')
|
| 22 |
|
| 23 |
# Look for the heading that contains the year
|
|
|
|
| 32 |
result = f"Unable to find specific dates for Burning Man {current_year}."
|
| 33 |
else:
|
| 34 |
result = f"Unable to find information for Burning Man {current_year}."
|
| 35 |
+
except requests.exceptions.RequestException as e:
|
| 36 |
+
logger.error(f"Error fetching Burning Man dates: {str(e)}")
|
| 37 |
+
result = f"Unable to fetch event dates at the moment. Error: {str(e)}"
|
| 38 |
+
except Exception as e:
|
| 39 |
+
logger.error(f"Unexpected error in get_burning_man_dates: {str(e)}")
|
| 40 |
+
result = f"An unexpected error occurred while fetching event dates. Error: {str(e)}"
|
| 41 |
|
| 42 |
+
logger.info(result)
|
| 43 |
+
return result
|