-
Notifications
You must be signed in to change notification settings - Fork 0
/
pollbot.py
executable file
·69 lines (59 loc) · 1.56 KB
/
pollbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python
"""
Telegram polling using a bot
"""
import os
import json
import datetime
import requests
try:
TOKEN = os.environ['TOKEN']
except KeyError:
TOKEN = "Token not available!"
try:
CHAT_ID = os.environ['CHAT_ID']
except KeyError:
CHAT_ID = "Chat ID not available!"
base_url = "https://api.telegram.org/bot"+TOKEN+"/sendPoll"
today = datetime.date.today()
closing_date = today + datetime.timedelta(days = 8)
year, WEEK_NUM, day_of_week = today.isocalendar()
if WEEK_NUM == 52:
WEEK_NUM = 0
NEXT_WEEK = str(WEEK_NUM + 1)
parameters = {
"chat_id" : CHAT_ID,
"question" : "Kochen W"+NEXT_WEEK,
"options" : json.dumps([
"Montag",
"Dienstag",
"Mittwoch",
"Donnerstag",
"Freitag",
"nur Ergebnisse sehen"
]),
"is_anonymous" : False,
"public_voters": True,
"allows_multiple_answers": True,
"close_poll": closing_date
}
parameters2 = {
"chat_id" : CHAT_ID,
"question" : "Essen W"+NEXT_WEEK,
"options" : json.dumps([
"Montag",
"Dienstag",
"Mittwoch",
"Donnerstag",
"Freitag",
"nur Ergebnisse sehen"
]),
"is_anonymous" : False,
"public_voters": True,
"allows_multiple_answers": True,
"close_poll": closing_date
}
response = requests.get(base_url, data = parameters, timeout=60)
response2 = requests.get(base_url, data = parameters2, timeout=60)
#print(response.text)
#print(response2.text)