BurnerBot / utils /events.py
Abhlash's picture
events
ea755df verified
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import logging
logger = logging.getLogger(__name__)
def get_burning_man_dates():
current_year = datetime.now().year
logger.info(f"{current_year} is the current year")
url = "https://burningman.org/"
headers = {
'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'
}
try:
response = requests.get(url, timeout=10, headers=headers)
response.raise_for_status() # This will raise an HTTPError for bad responses
soup = BeautifulSoup(response.content, 'html.parser')
# Look for the heading that contains the year
year_heading = soup.find('h1', string=lambda text: str(current_year) in text if text else False)
if year_heading:
# Find the paragraph that follows the year heading
date_paragraph = year_heading.find_next('p')
if date_paragraph:
result = f"Burning Man {current_year}: {date_paragraph.text.strip()}"
else:
result = f"Unable to find specific dates for Burning Man {current_year}."
else:
result = f"Unable to find information for Burning Man {current_year}."
except requests.exceptions.RequestException as e:
logger.error(f"Error fetching Burning Man dates: {str(e)}")
result = f"Unable to fetch event dates at the moment. Error: {str(e)}"
except Exception as e:
logger.error(f"Unexpected error in get_burning_man_dates: {str(e)}")
result = f"An unexpected error occurred while fetching event dates. Error: {str(e)}"
logger.info(result)
return result