setup first try

This commit is contained in:
2024-11-16 23:37:47 +03:30
parent ff1a28ebdf
commit c0c7342091
4 changed files with 46 additions and 8 deletions

View File

@@ -5,7 +5,7 @@ on:
branches:
- main
schedule:
- cron: "0 * * * *"
- cron: "30 3-21/6 * * *"
jobs:
run-script:

20
blockout.py Normal file
View File

@@ -0,0 +1,20 @@
import requests
from bs4 import BeautifulSoup
def get_main_page() -> str:
return requests.get('https://www.qepd.co.ir/').text
def find_blockout_link(html: str) -> None | str:
soup = BeautifulSoup(html, 'html.parser')
a_tags = soup.find_all('a', href=True)
for a_tag in filter(lambda tag: 'اطلاعات برنامه خاموشی ها' in tag.text, a_tags):
return a_tag.get('href')
return None
page = get_main_page()
link = find_blockout_link(page)
if not link:
raise Exception('unable to find blockout link!')

29
main.py
View File

@@ -1,6 +1,7 @@
import os
import time
import requests
from bs4 import BeautifulSoup
token = os.getenv("EITAAYAR_TOKEN")
chat_id = os.getenv("CHAT_ID")
@@ -11,14 +12,30 @@ if not token:
if not chat_id:
raise EnvironmentError("CHAT_ID is not set!")
def send_message(text: str) -> dict:
sent_at: int = int(time.time())
url = f'https://eitaayar.ir/api/{token}/sendMessage?chat_id={chat_id}&text={text}&title={sent_at=}'
return requests.get(url).json()
response = send_message('test')
if not response.get('ok'):
if response.get('description'):
raise Exception(response.get('description'))
else:
raise Exception('something sent wrong!')
def get_blockout_page() -> str:
blockout_link = 'https://qepd.co.ir/fa-IR/DouranPortal/6423'
return requests.get(blockout_link).text
def main() -> None:
page = get_blockout_page()
soup = BeautifulSoup(page, 'html.parser')
table = soup.find('table', id='ctl01_ctl00_myDataList').get_text(separator='\n', strip=True)
response = send_message(table)
if not response.get('ok'):
if response.get('description'):
raise Exception(response.get('description'))
else:
raise Exception('something sent wrong!')
if __name__ == '__main__':
main()

View File

@@ -1 +1,2 @@
requests
requests
beautifulsoup4