21
loading...
This website collects cookies to deliver better user experience
curl https://api.telegram.org/bot<bot_token>/getUpdates| python -m json.tool
"chat": {
"id": xxxxxxxxxxx,
"title": "Test_call",
"type": "channel"
},
import requests
def sendToTelegram(message,chat_id,bot_token):
response = requests.post(
url=f'https://api.telegram.org/bot{bot_token}/sendMessage',
data={"chat_id": chat_id, "text": message, "disable_notification": True }
).json()
Note
: You can use bots to send message to channels. But there is some limitation, like size of files.# Let's read from cowin
headers = {
'authority': 'cdn-api.co-vin.in',
'sec-ch-ua': '"Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"',
'accept': 'application/json, text/plain, */*',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36',
'origin': 'https://www.cowin.gov.in',
'sec-fetch-site': 'cross-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://www.cowin.gov.in/',
'accept-language': 'en-IN,en-GB;q=0.9,en-US;q=0.8,en;q=0.7',
}
params = (
('district_id', district_id),
('date',date),
)
response = requests.get('https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict', headers=headers, params=params)
params = (('pincode', pincode),
('date',date),
)
response = requests.get('https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByPin', headers=headers, params=params)
import pandas as pd
result_df = pd.DataFrame()
# First check if response is correct or not
if response.status_code == 200:
dict_response = json.loads(response.text)
if 'centers' in dict_response :
df = pd.DataFrame(dict_response['centers'])
# Here I'm applying filters
df = df[df.fee_type == "Free"]
result_df = result_df.append(df, ignore_index = True)
else:
print(dict_response,type(dict_response))
else:
# If api request failed
print(response.status_code,response.text)
age = 18 # Since I want to select slots where minimum age is 18 not 45
message = ""
for center_id, df in result_df.groupby("center_id"):
for index, row in df.iterrows():
available_capacity1 = 0
available_capacity2 = 0
for s in row["sessions"]:
if s["min_age_limit"] == age:
available_capacity1 = s["available_capacity_dose1"]
available_capacity2 = s["available_capacity_dose2"]
if available_capacity1 + available_capacity2 > 0:
message+="Dose 1: %s,Dose 2: %s, Slot Available at %s, pincode %s\n"%(available_capacity1,available_capacity2,row['name'],row['pincode'])
# chances are there no slot available
if len(message) > 0:
return message