Last active
October 29, 2022 08:47
-
-
Save arsalanses/a2e4e2d04cedc021eba0561328f0e2c3 to your computer and use it in GitHub Desktop.
Telegram bot that reads list of jalali dates from csv formatted file and send msg on those dates
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
import jdatetime | |
import requests | |
import schedule | |
import time | |
import csv | |
GROUP_ID = '' | |
BOT_TOKEN = '' | |
BASE_URL = f'https://api.telegram.org/bot{BOT_TOKEN}/sendMessage?chat_id={GROUP_ID}&text=' | |
def job(): | |
with open('data.csv', 'r') as file: | |
reader = csv.reader(file) | |
flag = True | |
for row in reader: | |
if(str(row[0]) == str(jdatetime.date.today())): | |
flag = False | |
text = f"{row[2]}\n{row[1]}\n{row[0]}" | |
res = requests.get(f'{BASE_URL}{text}').json() | |
if flag: | |
res = requests.get(f'{BASE_URL}Enjoy you shitty day!').json() | |
schedule.every().day.at("07:50").do(job) | |
while True: | |
schedule.run_pending() | |
time.sleep(15) | |
# python -m venv venv | |
# source venv/bin/activate | |
# pip install jdatetime requests | |
# crontab -e | |
# https://crontab.guru/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment