Spaces:
Paused
Paused
| import time | |
| import requests | |
| import random | |
| import string | |
| from bs4 import BeautifulSoup | |
| import os | |
| WEBHOOK_URL = os.environ['web'] | |
| BASE_URL = "https://discord.nfp.is/" | |
| VIDEO_CHECK_INTERVAL = 1 | |
| def generate_random_string(length=3): | |
| return ''.join(random.choices(string.ascii_letters, k=length)) | |
| def send_webhook_message(video_link): | |
| data = { | |
| "content": video_link | |
| } | |
| response = requests.post(WEBHOOK_URL, json=data) | |
| if response.status_code != 204: | |
| return | |
| def check_site_content(url, random_string): | |
| try: | |
| response = requests.get(url) | |
| if response.status_code == 200: | |
| soup = BeautifulSoup(response.content, 'html.parser') | |
| pre_tag = soup.find('pre') | |
| if pre_tag and random_string in pre_tag.text: | |
| return True | |
| return False | |
| except requests.RequestException as e: | |
| return False | |
| def main(): | |
| while True: | |
| try: | |
| random_string = generate_random_string() | |
| video_link = BASE_URL + random_string | |
| if check_site_content(video_link, random_string): | |
| send_webhook_message(video_link) | |
| else: | |
| print(f"this shit {video_link} does not exist") | |
| time.sleep(VIDEO_CHECK_INTERVAL) | |
| except Exception as e: | |
| print(f"error {e}") | |
| if __name__ == "__main__": | |
| main() |