Skip to content

Commit

Permalink
Add protocol checking & update WEBSITE_URL on the go
Browse files Browse the repository at this point in the history
Check if the website is accessible using https, if not then use http if it's working. Also update the WEBSITE_URL value accordingly.
  • Loading branch information
origamiofficial committed Apr 28, 2024
1 parent c71fdd0 commit 499600d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
TELEGRAM_ADMIN_CHAT_ID = os.environ.get("TELEGRAM_ADMIN_CHAT_ID")
TELEGRAM_BOT_API_KEY = os.environ["TELEGRAM_BOT_API_KEY"]
GITHUB_RUN_NUMBER = os.environ["GITHUB_RUN_NUMBER"]
PROTOCOLS = ["https://", "http://"]
NOTICE_PAGE = "www.aiub.edu/category/notices/"
WEBSITE_URL = None # DO NOT CHANGE

# URL and XPath information for AIUB Notice page
WEBSITE_URL = "https://www.aiub.edu/category/notices/"
# XPath information for AIUB Notice page
POST_XPATH = "//ul[@class='event-list']/li"
TITLE_XPATH = ".//h2[@class='title']/text()"
LINK_XPATH = ".//a[@class='info-link']/@href"
Expand Down Expand Up @@ -74,11 +76,18 @@

# Check if AIUB website is up
print("Checking if AIUB website is up...")
try:
requests.get(WEBSITE_URL)
print("AIUB website is up.")
except requests.ConnectionError as e:
print(f"AIUB website is down: {e}. Exiting script.")
for protocol in PROTOCOLS:
try:
response = requests.get(protocol + NOTICE_PAGE)
if response.status_code == 200:
WEBSITE_URL = protocol + NOTICE_PAGE
print(f"AIUB website is up. Protocol: {protocol} is working.")
break
except requests.exceptions.RequestException as e:
print(f"Error trying {protocol}: {e}")

if WEBSITE_URL is None:
print("AIUB website is down. Exiting script.")
exit()

# Function to send admin notification
Expand Down

0 comments on commit 499600d

Please sign in to comment.