-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram1_bot.py
More file actions
208 lines (113 loc) · 4.01 KB
/
Copy pathtelegram1_bot.py
File metadata and controls
208 lines (113 loc) · 4.01 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import requests
from datetime import datetime
from telegram import Update
from telegram.ext import ApplicationBuilder, CommandHandler, ContextTypes
BOT_TOKEN = "your api key "
API_URL = "http://127.0.0.1:8000"
# ---------------- START ----------------
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
msg = """
🙏 *Ekadashi Reminder Bot*
Available Commands:
📅 */today*
Check if today is Ekadashi
🌙 */tomorrow*
Check if tomorrow is Ekadashi
🪔 */next*
Next upcoming Ekadashi
📜 */year 2026*
Show all Ekadashis of a year
🔎 */check 2026-03-15*
Check specific date
"""
await update.message.reply_text(msg, parse_mode="Markdown")
# ---------------- TODAY ----------------
async def today(update: Update, context: ContextTypes.DEFAULT_TYPE):
data = requests.get(f"{API_URL}/today").json()
if data["is_ekadashi"]:
msg = """
🌼 *Today is Ekadashi*
A sacred day for fasting and devotion 🙏
"""
else:
msg = "❌ Today is not Ekadashi."
await update.message.reply_text(msg, parse_mode="Markdown")
# ---------------- TOMORROW ----------------
async def tomorrow(update: Update, context: ContextTypes.DEFAULT_TYPE):
data = requests.get(f"{API_URL}/tomorrow").json()
if data["is_ekadashi"]:
msg = """
🌙 *Tomorrow is Ekadashi*
Prepare yourself mentally and spiritually 🙏
"""
else:
msg = "Tomorrow is not Ekadashi."
await update.message.reply_text(msg, parse_mode="Markdown")
# ---------------- NEXT EKADASHI ----------------
async def next_ek(update: Update, context: ContextTypes.DEFAULT_TYPE):
data = requests.get(f"{API_URL}/next").json()
msg = f"""
🪔 *Next Ekadashi*
📅 Date: *{data['date']}*
🌗 Paksha: *{data['paksha']}*
⏳ Days remaining: *{data['days_until']}*
Stay prepared 🙏
"""
await update.message.reply_text(msg, parse_mode="Markdown")
# ---------------- YEAR CALENDAR ----------------
async def year(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not context.args:
await update.message.reply_text("Usage: /year 2026")
return
year = context.args[0]
data = requests.get(f"{API_URL}/year/{year}").json()
krishna = []
shukla = []
for e in data["dates"]:
date = datetime.strptime(e["date"], "%Y-%m-%d")
formatted = date.strftime("%d %b")
if e["paksha"] == "Krishna":
krishna.append(formatted)
else:
shukla.append(formatted)
msg = f"📜 *Ekadashi Calendar — {year}*\n\n"
msg += "🌑 *Krishna Paksha*\n"
for d in krishna:
msg += f"• {d}\n"
msg += "\n🌕 *Shukla Paksha*\n"
for d in shukla:
msg += f"• {d}\n"
msg += f"\n✨ Total Ekadashis: *{data['total']}*"
await update.message.reply_text(msg, parse_mode="Markdown")
# ---------------- CHECK DATE ----------------
async def check(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not context.args:
await update.message.reply_text("Usage: /check YYYY-MM-DD")
return
date = context.args[0]
data = requests.get(f"{API_URL}/check/{date}").json()
if "error" in data:
await update.message.reply_text(data["error"])
return
if data["is_ekadashi"]:
msg = f"""
✅ *{date} is Ekadashi*
Observe fasting and devotion 🙏
"""
else:
msg = f"❌ {date} is not Ekadashi."
await update.message.reply_text(msg, parse_mode="Markdown")
# ---------------- MAIN ----------------
def main():
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CommandHandler("today", today))
app.add_handler(CommandHandler("tomorrow", tomorrow))
app.add_handler(CommandHandler("next", next_ek))
app.add_handler(CommandHandler("year", year))
app.add_handler(CommandHandler("check", check))
print("Ekadashi Telegram Bot Running...")
app.run_polling()
if __name__ == "__main__":
main()
##CHAT_ID = "7690163799"