-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSciBot.py
More file actions
602 lines (512 loc) · 21 KB
/
Copy pathSciBot.py
File metadata and controls
602 lines (512 loc) · 21 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
import Assets as keys
from telegram.ext import *
import Responses as R
from datetime import datetime
import requests
from bs4 import BeautifulSoup
import wikipedia
import calendar
flag = 0
print("Bot has started...")
def start_command(update, context): #/start
user = update.message.from_user
update.message.reply_text('Hello @{} ! '.format(user['username']))
global start
def help_command(update, context): #/help
update.message.reply_text('Displaying commands for SciFiBot:')
update.message.reply_text('''/time - display the time
/date - display the date today
/calc - calculate any bodmas equation''')
def date_command(update,context):
now = datetime.now()
date_time = now.strftime("%d/%m/%y")
x = str(date_time)
update.message.reply_text(x)
def time_command(update,context):
now = datetime.now()
date_time = now.strftime("%H:%M:%S")
update.message.reply_text(date_time)
def calc_command(update,context):
global flag
flag = 1
update.message.reply_text("What do u wanna calculate?")
def search_command(update,context):
global flag
flag = 3
update.message.reply_text("What do u wanna search for?")
def wiki_command(update,context):
global flag
flag = 5
update.message.reply_text("What do you wanna search for?")
def google_command(update,context):
global flag
flag = 7
update.message.reply_text("What do you wanna search for?")
def image_command(update,context):
global flag
flag = 9
update.message.reply_text("What do you wanna search for?")
#?This thing doesn't work due to API
#*Doesn't refresh the API page
#TODO: It should work for USA AND UK, etc.
def cases_command(update,context):
req = requests.get("https://api.covid19api.com/summary")
if req.status_code == 200:
data = req.json()
Formatted_strings ="""The Newly confirmed cases are {newc}
The Total confirmed cases are {tc}
The newly confirmed deaths are {newd}
The Total confirmed deaths are {td}
The newly recovered cases are {newr}""".format(newc = data['Global']['NewConfirmed'],tc =data['Global']['TotalConfirmed'],newd =data['Global']['NewDeaths'], td = data['Global']['TotalDeaths'], newr = data['Global']['NewRecovered'])
update.message.reply_text(Formatted_strings)
#*I need your code man
def country_cases_command(update,context):
global flag
flag = 11
update.message.reply_text("Which country's cases do you wanna check for?")
global country
country = update.message.text()
#?No idea why this is not working
def bold_command(update,context):
global flag
flag = 13
update.message.reply_text("Provide your text and it will be made bold")
global sample
sample = update.message.text()
def next_per_command(update,context):
from datetime import datetime
def findDay(date):
born = datetime.strptime(date, '%d %m %Y').weekday()
return (calendar.day_name[born])
now = datetime.now()
y = now.strftime("%Y")
m = now.strftime("%m")
d = now.strftime("%d")
date = d +" "+ m +" "+ y
day = findDay(date)
from datetime import datetime
current = datetime.now()
h = current.strftime("%H")
m = current.strftime("%M")
time = int((int(h)*60) + int(m))
if day == "Monday":
if time <540:
next_class = "Social"
elif time < 590 and time > 540:
next_class="Hindi"
elif time < 640 and time > 590:
next_class="Chemistry"
elif time < 690 and time > 640:
next_class="Maths"
elif time < 740 and time > 690:
next_class="English"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Free Period!"
else:
next_class = "Classes are done"
if day == "Tuesday":
if time <540:
next_class = "Hindi"
elif time < 590 and time > 540:
next_class="Maths"
elif time < 640 and time > 590:
next_class="Free Period!"
elif time < 690 and time > 640:
next_class="Social"
elif time < 740 and time > 690:
next_class="Hindi"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Chemistry"
else:
next_class = "Classes are done"
if day == "Wednesday":
if time <540:
next_class = "Social"
elif time < 590 and time > 540:
next_class="Art"
elif time < 640 and time > 590:
next_class="Free Period!"
elif time < 690 and time > 640:
next_class="English"
elif time < 740 and time > 690:
next_class="Hindi"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Biology"
else:
next_class = "Classes are done"
if day == "Thursday":
if time <540:
next_class = "English"
elif time < 590 and time > 540:
next_class="Hindi"
elif time < 640 and time > 590:
next_class="Physics"
elif time < 690 and time > 640:
next_class="Free Period!"
elif time < 740 and time > 690:
next_class="Social"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Math"
else:
next_class = "Classes are done"
if day == "Friday":
if time <540:
next_class = "English"
elif time < 590 and time > 540:
next_class="Physics"
elif time < 640 and time > 590:
next_class="Computers"
elif time < 690 and time > 640:
next_class="Maths"
elif time < 740 and time > 690:
next_class="Social"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Free Period!"
else:
next_class = "Classes are done"
if day == "Saturday":
if time <540:
next_class = "Social"
elif time < 590 and time > 540:
next_class="Free period"
elif time < 640 and time > 590:
next_class="Bio"
elif time < 690 and time > 640:
next_class="Maths"
elif time < 740 and time > 690:
next_class="Maths"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Free Period!"
else:
next_class = "Classes are done"
update.message.reply_text(next_class)
def photo_command(update,context):
pass
def handle_message(update, context):
global flag
while flag==0:
text = str(update.message.text).lower()
if text in ("hello", "hi", "hey"):
update.message.reply_text("Hey, how's it going?")
break
if text in ("how're you?", "how are you", "how are you?"):
update.message.reply_text("I am great!")
break
if text in ("who are you?", "who're you?", "who are you"):
update.message.reply_text ("I am SciFiBot")
break
if text in ("what is the time?", "tell me the time", "time please", "time.", "time"):
now = datetime.now()
date_time = now.strftime("%H:%M:%S")
update.message.reply_text(str(date_time))
break
if text in ("what is the date?","what is the date today?", "what is today's date", "tell me the date", "date please", "date.", "date"):
now = datetime.now()
date_time = now.strftime("%d/%m/%y")
update.message.reply_text(str(date_time))
break
if text in ("thank you","thanks"):
update.message.reply_text("👍")
update.message.reply_text("np boi, np")
flag = 1
if text in ("bye.", "bye"):
update.message.reply_text("bye👋🏻")
break
if text in ("fine", "i am fine", "good", "i am good", "i am good.", "great!", "great", "great."):
update.message.reply_text("what can i do for you?")
break
if "calculate" in text:
text = text.replace("calculate","")
update.message.reply_text(eval(text))
break
if "search" in text:
#Google
text = text.replace("search","")
splitted = text.split()
length = len(splitted)
search_link = "https://www.google.com/search?q="
for word in range(length):
search_link = search_link + str(splitted[word])+"+"
update.message.reply_text(search_link+"&rlz=1C1NHXL_enIN704IN704")
#Wikipedia
wiki_link = "https://en.wikipedia.org/wiki/"
for word in range(length):
wiki_link = wiki_link + str(splitted[word])+"_"
update.message.reply_text(wiki_link)
results = wikipedia.summary(text, sentences=4)
update.message.reply_text('According to wikipedia')
update.message.reply_text(results)
break
if text in "gs":
text = text.replace("gs","")
splitted = text.split()
length = len(splitted)
search_link = "https://www.google.com/search?q="
search_link = "https://www.google.com/search?q="
for word in range(length):
search_link = search_link + str(splitted[word])+"+"
update.message.reply_text(search_link+"&rlz=1C1NHXL_enIN704IN704")
break
if text in "ws":
text = text.replace("ws","")
splitted = text.split()
length = len(splitted)
wiki_link = "https://en.wikipedia.org/wiki/"
for word in range(length):
wiki_link = wiki_link + str(splitted[word])+"_"
update.message.reply_text(wiki_link)
results = wikipedia.summary(text, sentences=4)
update.message.reply_text('According to wikipedia')
update.message.reply_text(results)
break
if "is" in text:
text = text.replace("is","")
toSearch = text
splited= toSearch.split()
length = len(splited)
search_link = "https://www.google.com/search?q="
for x in range(0,length):
search_link = search_link + splited[x] + "+"
search_link = search_link + "&rlz=1C1NHXL_enIN704IN704&ie=UTF-8&source=lnms&tbm=isch&sa=X&ved=0ahUKEwivo-baz-zvAhWWfd4KHSXRC_UQ_AUICCgB"
reqs = requests.get(search_link)
soup = BeautifulSoup(reqs.text, 'html.parser')
srcs = []
for img in soup.find_all('img'):
src = img.get('src')
srcs.append(src)
outputs = srcs[1:6]
for output in outputs:
update.message.reply_text(output)
if text in ("next_per","np","n_p"):
from datetime import datetime
def findDay(date):
born = datetime.strptime(date, '%d %m %Y').weekday()
return (calendar.day_name[born])
now = datetime.now()
y = now.strftime("%Y")
m = now.strftime("%m")
d = now.strftime("%d")
date = d +" "+ m +" "+ y
day = findDay(date)
from datetime import datetime
current = datetime.now()
h = current.strftime("%H")
m = current.strftime("%M")
time = int((int(h)*60) + int(m))
if day == "Monday":
if time <540:
next_class = "Social"
elif time < 590 and time > 540:
next_class="Hindi"
elif time < 640 and time > 590:
next_class="Chemistry"
elif time < 690 and time > 640:
next_class="Maths"
elif time < 740 and time > 690:
next_class="English"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Free Period!"
else:
next_class = "Classes are done"
if day == "Tuesday":
if time <540:
next_class = "Hindi"
elif time < 590 and time > 540:
next_class="Maths"
elif time < 640 and time > 590:
next_class="Free Period!"
elif time < 690 and time > 640:
next_class="Social"
elif time < 740 and time > 690:
next_class="Hindi"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Chemistry"
else:
next_class = "Classes are done"
if day == "Wednesday":
if time <540:
next_class = "Social"
elif time < 590 and time > 540:
next_class="Art"
elif time < 640 and time > 590:
next_class="Free Period!"
elif time < 690 and time > 640:
next_class="English"
elif time < 740 and time > 690:
next_class="Hindi"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Biology"
else:
next_class = "Classes are done"
if day == "Thursday":
if time <540:
next_class = "English"
elif time < 590 and time > 540:
next_class="Hindi"
elif time < 640 and time > 590:
next_class="Physics"
elif time < 690 and time > 640:
next_class="Free Period!"
elif time < 740 and time > 690:
next_class="Social"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Math"
else:
next_class = "Classes are done"
if day == "Friday":
if time <540:
next_class = "English"
elif time < 590 and time > 540:
next_class="Physics"
elif time < 640 and time > 590:
next_class="Computers"
elif time < 690 and time > 640:
next_class="Maths"
elif time < 740 and time > 690:
next_class="Social"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Free Period!"
else:
next_class = "Classes are done"
if day == "Saturday":
if time <540:
next_class = "Social"
elif time < 590 and time > 540:
next_class="Free period"
elif time < 640 and time > 590:
next_class="Bio"
elif time < 690 and time > 640:
next_class="Maths"
elif time < 740 and time > 690:
next_class="Maths"
elif time < 780 and time > 740:
next_class = "Lunch"
elif time < 830:
next_class = "Free Period!"
else:
next_class = "Classes are done"
update.message.reply_text(next_class)
break
if text in ("woohoo","woohoo!","woohoo!!","yay!","awesomeness!","awesomeness"):
update.message.reply_text("🥳")
break
else:
update.message.reply_text("Sorry, I don't understand you")
break
if flag == 1:
text = str(update.message.text).lower()
update.message.reply_text(eval(text))
flag = 0
if flag == 3:
text = str(update.message.text).lower()
splitted = text.split()
length = len(splitted)
search_link = "https://www.google.com/search?q="
for word in range(length):
search_link = search_link + str(splitted[word])+"+"
update.message.reply_text(search_link+"&rlz=1C1NHXL_enIN704IN704")
#Wikipedia
wiki_link = "https://en.wikipedia.org/wiki/"
for word in range(length):
wiki_link = wiki_link + str(splitted[word])+"_"
update.message.reply_text(wiki_link)
results = wikipedia.summary(text, sentences=4)
update.message.reply_text('According to wikipedia')
update.message.reply_text(results)
flag = 2
if flag == 5:
text = str(update.message.text).lower()
splitted = text.split()
length = len(splitted)
wiki_link = "https://en.wikipedia.org/wiki/"
for word in range(length):
wiki_link = wiki_link + str(splitted[word])+"_"
update.message.reply_text(wiki_link)
results = wikipedia.summary(text, sentences=4)
update.message.reply_text('According to wikipedia')
update.message.reply_text(results)
flag = 4
if flag == 7:
text = str(update.message.text).lower()
splitted = text.split()
length = len(splitted)
search_link = "https://www.google.com/search?q="
search_link = "https://www.google.com/search?q="
for word in range(length):
search_link = search_link + str(splitted[word])+"+"
update.message.reply_text(search_link+"&rlz=1C1NHXL_enIN704IN704")
flag = 6
if flag == 9:
text = str(update.message.text).lower()
toSearch = text
splited= toSearch.split()
length = len(splited)
search_link = "https://www.google.com/search?q="
for x in range(0,length):
search_link = search_link + splited[x] + "+"
search_link = search_link + "&rlz=1C1NHXL_enIN704IN704&ie=UTF-8&source=lnms&tbm=isch&sa=X&ved=0ahUKEwivo-baz-zvAhWWfd4KHSXRC_UQ_AUICCgB"
reqs = requests.get(search_link)
soup = BeautifulSoup(reqs.text, 'html.parser')
srcs = []
for img in soup.find_all('img'):
src = img.get('src')
srcs.append(src)
outputs = srcs[1:6]
for output in outputs:
update.message.reply_text(output)
flag = 8
if flag == 11:
req = requests.get("https://api.covid19api.com/summary")
if req.status_code == 200:
data = req.json()
global co
country = country.upper()
if data['Countries'][""]['Country'] == country:
print("Success!!")
if flag == 13:
print(f"**{sample}**")
def error(update, context):
print(f"Update {update} caused error {context.error}")
def main():
updater = Updater(keys.API_KEY, use_context = True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start_command))
dp.add_handler(CommandHandler("help", help_command))
dp.add_handler(CommandHandler("calc", calc_command))
dp.add_handler(CommandHandler("date", date_command))
dp.add_handler(CommandHandler("time", time_command))
dp.add_handler(CommandHandler("next_per", next_per_command))
dp.add_handler(CommandHandler("search", search_command))
dp.add_handler(CommandHandler("wiki", wiki_command))
dp.add_handler(CommandHandler("google", google_command))
dp.add_handler(CommandHandler("image", image_command))
dp.add_handler(CommandHandler("cases", cases_command))
dp.add_handler(CommandHandler("c_cases", country_cases_command))
dp.add_handler(CommandHandler("bold", bold_command))
dp.add_handler(MessageHandler(Filters.text, handle_message))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
main()