forked from reaprx/Sri-lankan-Exam-Results-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
119 lines (103 loc) · 3.82 KB
/
bot.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
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
import telebot
import re
import requests
import json
import os
bot = telebot.TeleBot(os.environ.get("BOT_TOKEN"))
wel_mes = """Hello I can find exam results.
/help for more info """
help_mes = """To check Results send Index Number like this.
/al {Index nNumber} - To get AL Rsults
/ol {Index nNumber} - To get OL Rsults
/g5 {Index nNumber} - To get Grade 5 Scholarship Exam Rsults
e.g. :- /ol 6162XXXX"""
er_mes="Send with index number."
error_mes = "Something went wrong. Please try again later."
def alresult(inumber):
try:
result_json = requests.get("https://www.doenets.lk/result/service/AlResult/"+inumber)
re = json.loads(result_json.text)
res = """Exam - {}
Year - {}
Name - {}
Index Number - {}
NIC Number - {}
District Rank - {}
Island Rank - {}
ZScore - {}
Subject Stream - {}
{} - {}
{} - {}
{} - {}
{} - {}
{} - {}"""
res=res.format(re['examination'], re['year'], re['name'], re['indexNo'], re['nic'], re['districtRank'], re['islandRank'], re['zScore'], re['stream'], re['subjectResults'][0]['subjectName'], re['subjectResults'][0]['subjectResult'], re['subjectResults'][1]['subjectName'], re['subjectResults'][1]['subjectResult'], re['subjectResults'][2]['subjectName'], re['subjectResults'][2]['subjectResult'], re['subjectResults'][3]['subjectName'], re['subjectResults'][3]['subjectResult'], re['subjectResults'][4]['subjectName'], re['subjectResults'][4]['subjectResult'])
return res
except:
return error_mes
def olresult(inumber):
try:
result_json = requests.get("https://www.doenets.lk/result/service/OlResult/"+inumber)
re = json.loads(result_json.text)
res = """Exam - {}
Year - {}
Name - {}
Index Number - {}
{} - {}
{} - {}
{} - {}
{} - {}
{} - {}
{} - {}
{} - {}
{} - {}
{} - {}"""
res=res.format(re['examination'], re['year'], re['name'], re['indexNo'], re['subjectResults'][0]['subjectName'], re['subjectResults'][0]['subjectResult'], re['subjectResults'][1]['subjectName'], re['subjectResults'][1]['subjectResult'], re['subjectResults'][2]['subjectName'], re['subjectResults'][2]['subjectResult'], re['subjectResults'][3]['subjectName'], re['subjectResults'][3]['subjectResult'], re['subjectResults'][4]['subjectName'], re['subjectResults'][4]['subjectResult'], re['subjectResults'][5]['subjectName'], re['subjectResults'][5]['subjectResult'], re['subjectResults'][6]['subjectName'], re['subjectResults'][6]['subjectResult'], re['subjectResults'][7]['subjectName'], re['subjectResults'][7]['subjectResult'], re['subjectResults'][8]['subjectName'], re['subjectResults'][8]['subjectResult'] )
return res
except:
return error_mes
def g5result(inumber):
try:
result_json = requests.get("https://www.doenets.lk/result/service/GvResult/"+inumber)
re = json.loads(result_json.text)
res = """Exam - {}
Year - {}
Name - {}
Index Number - {}
Marks - {}
District Rank - {} """
res = res.format(re['examination'], re['year'], re['name'], re['indexNo'], re['marks'], re['districtRank'] )
return res
except:
return error_mes
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, wel_mes)
@bot.message_handler(commands=['help'])
def send_help(message):
bot.reply_to(message, help_mes)
@bot.message_handler(commands=['al','AL','Al'])
def send_al(message):
x = re.split("\s", message.text)
try:
rslt=alresult(x[1])
bot.reply_to(message,rslt)
except:
bot.reply_to(message,er_mes)
@bot.message_handler(commands=['ol','OL','Ol'])
def send_ol(message):
x = re.split("\s", message.text)
try:
rslt=olresult(x[1])
bot.reply_to(message, rslt)
except:
bot.reply_to(message,er_mes)
@bot.message_handler(commands=['g5','G5'])
def send_g5(message):
x = re.split("\s", message.text)
try:
rslt=g5result(x[1])
bot.reply_to(message, rslt)
except:
bot.reply_to(message,er_mes)
bot.polling()