setup first try
This commit is contained in:
2
.github/workflows/run-script.yml
vendored
2
.github/workflows/run-script.yml
vendored
@@ -5,7 +5,7 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 * * * *"
|
- cron: "30 3-21/6 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-script:
|
run-script:
|
||||||
|
|||||||
20
blockout.py
Normal file
20
blockout.py
Normal 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!')
|
||||||
19
main.py
19
main.py
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
token = os.getenv("EITAAYAR_TOKEN")
|
token = os.getenv("EITAAYAR_TOKEN")
|
||||||
chat_id = os.getenv("CHAT_ID")
|
chat_id = os.getenv("CHAT_ID")
|
||||||
@@ -11,14 +12,30 @@ if not token:
|
|||||||
if not chat_id:
|
if not chat_id:
|
||||||
raise EnvironmentError("CHAT_ID is not set!")
|
raise EnvironmentError("CHAT_ID is not set!")
|
||||||
|
|
||||||
|
|
||||||
def send_message(text: str) -> dict:
|
def send_message(text: str) -> dict:
|
||||||
sent_at: int = int(time.time())
|
sent_at: int = int(time.time())
|
||||||
url = f'https://eitaayar.ir/api/{token}/sendMessage?chat_id={chat_id}&text={text}&title={sent_at=}'
|
url = f'https://eitaayar.ir/api/{token}/sendMessage?chat_id={chat_id}&text={text}&title={sent_at=}'
|
||||||
return requests.get(url).json()
|
return requests.get(url).json()
|
||||||
|
|
||||||
response = send_message('test')
|
|
||||||
|
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 not response.get('ok'):
|
||||||
if response.get('description'):
|
if response.get('description'):
|
||||||
raise Exception(response.get('description'))
|
raise Exception(response.get('description'))
|
||||||
else:
|
else:
|
||||||
raise Exception('something sent wrong!')
|
raise Exception('something sent wrong!')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
requests
|
requests
|
||||||
|
beautifulsoup4
|
||||||
Reference in New Issue
Block a user