Last active
December 4, 2024 12:25
-
-
Save AnmolTomer/906b6cbfa62209e3927a7c97c6598146 to your computer and use it in GitHub Desktop.
Checks on EA Server page if FC25 is down or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import requests | |
import pprint | |
url = 'https://help.ea.com/en/help/faq/are-ea-servers-down/' | |
def check_server_status(): | |
url = "https://help.ea.com/en/help/faq/are-ea-servers-down/" | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' | |
} | |
try: | |
print("Sending request to URL:", url) | |
response = requests.get(url, headers=headers, timeout=10) | |
print("Response status code:", response.status_code) | |
# print("Response headers:\n", pprint.pformat(response.headers)) | |
if response.status_code == 200: | |
print("Parsing HTML content") | |
soup = BeautifulSoup(response.content, 'html.parser') | |
# Print the entire HTML content for debugging | |
html_content = soup.prettify() | |
with open("page_content.html", "w", encoding="utf-8") as file: | |
file.write(html_content) | |
# print("HTML content written to page_content.html") | |
# print("Looking for anchor element with specific href") | |
anchor_element = soup.find('a', href="https://help.ea.com/help-top-issues/?product=fc-25") | |
if anchor_element: | |
# print("Anchor element found:", anchor_element) | |
img_element = anchor_element.find('img') | |
if img_element: | |
alt_text = img_element.get('alt', '') | |
# print("Image alt text:", alt_text) | |
is_offline = 'Server is offline' in alt_text | |
data = {'altText': alt_text, 'isOffline': is_offline} | |
return data['altText'] | |
else: | |
print("Image element not found in anchor element") | |
return "Image element not found in anchor element." | |
else: | |
print("Anchor element with specific href not found") | |
return "FC-25 server information not found." | |
else: | |
print(f"Failed to retrieve the page. Status code: {response.status_code}") | |
return f"Failed to retrieve the page. Status code: {response.status_code}" | |
except requests.exceptions.RequestException as e: | |
print("Error during requests to", url, ":", str(e)) | |
return "An error occurred while fetching the server status." | |
server_status = check_server_status() | |
print("Server status:", server_status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add sound and auto check every 15 minutes | |
from bs4 import BeautifulSoup | |
import requests | |
import pprint | |
import time | |
import winsound | |
url = 'https://help.ea.com/en/help/faq/are-ea-servers-down/' | |
def play_sound(): | |
# Play a sound on Windows. Change 'SystemExit' to the desired sound. | |
winsound.MessageBeep(winsound.MB_ICONEXCLAMATION) | |
def check_server_status(): | |
url = "https://help.ea.com/en/help/faq/are-ea-servers-down/" | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' | |
} | |
try: | |
print("Sending request to URL:", url) | |
response = requests.get(url, headers=headers, timeout=10) | |
print("Response status code:", response.status_code) | |
# print("Response headers:\n", pprint.pformat(response.headers)) | |
if response.status_code == 200: | |
print("Parsing HTML content") | |
soup = BeautifulSoup(response.content, 'html.parser') | |
# Print the entire HTML content for debugging | |
html_content = soup.prettify() | |
with open("page_content.html", "w", encoding="utf-8") as file: | |
file.write(html_content) | |
# print("HTML content written to page_content.html") | |
# print("Looking for anchor element with specific href") | |
anchor_element = soup.find('a', href="https://help.ea.com/help-top-issues/?product=fc-25") | |
if anchor_element: | |
# print("Anchor element found:", anchor_element) | |
img_element = anchor_element.find('img') | |
if img_element: | |
alt_text = img_element.get('alt', '') | |
# print("Image alt text:", alt_text) | |
is_offline = 'Server is offline' in alt_text | |
data = {'altText': alt_text, 'isOffline': is_offline} | |
return data['altText'] | |
else: | |
print("Image element not found in anchor element") | |
return "Image element not found in anchor element." | |
else: | |
print("Anchor element with specific href not found") | |
return "FC-25 server information not found." | |
else: | |
print(f"Failed to retrieve the page. Status code: {response.status_code}") | |
return f"Failed to retrieve the page. Status code: {response.status_code}" | |
except requests.exceptions.RequestException as e: | |
print("Error during requests to", url, ":", str(e)) | |
return "An error occurred while fetching the server status." | |
def main(): | |
while True: | |
server_status = check_server_status() | |
print("Server status:", server_status) | |
if "Server is online" in server_status: | |
play_sound() | |
# Wait for 10 minutes (600 seconds) | |
time.sleep(900) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment