This commit is contained in:
AB
2018-05-11 23:08:29 +03:00
parent 9a2d216691
commit da97ee7c99

View File

@ -10,6 +10,7 @@ import logging
import telegram
from telegram.error import NetworkError, Unauthorized
from time import sleep
from main import Perdoliq
update_id = None
@ -21,7 +22,8 @@ def main():
TOKEN = os.environ["TG_TOKEN"]
bot = telegram.Bot(TOKEN)
# get the first pending update_id, this is so we can skip over it in case
# get the first pending update_id,
# this is so we can skip over it in case
# we get an "Unauthorized" exception.
try:
update_id = bot.get_updates()[0].update_id
@ -38,17 +40,25 @@ def main():
# The user has removed or blocked the bot.
update_id += 1
def perdoliq(username, password, subj, test, acc):
try:
from main import Perdoliq
app = Perdoliq(username, password)
app.auth()
app.get_tests()
app.resolve(subj, test, acc, is_delayed=False)
except Exception as e:
return "Exception: " + str(e)
return "Exception: " + str(e)
def list_test(username, password):
try:
app = Perdoliq(username, password)
app.auth()
return (app.get_tests())
except Exception as e:
return "Exception: " + str(e)
def echo(bot):
"""Echo the message the user sent."""
@ -56,14 +66,32 @@ def echo(bot):
# Request updates after the last update_id
for update in bot.get_updates(offset=update_id, timeout=10):
update_id = update.update_id + 1
if update.message:
s = update.message.text.split()
if len(s) == 6:
msg = "usr: " + s[0] + " pass: " + s[1] + " subj: " + s[2] + " test: " + s[3] + " acc: " + s[4]
msg = "usr: " + \
s[0] + " pass: " + \
s[1] + " subj: " + \
s[2] + " test: " + \
s[3] + " acc: " + s[4]
perdoliq(s[0], s[1], s[2], s[3], s[4])
update.message.reply_text(msg)
else:
msg = "Usage: <user> <pass> <subj> <test> <accuracy>"
update.message.reply_text(msg)
if s[0] == 'list':
tests = list_test(s[1], s[2])
msg = ""
i = 0
for subj in tests:
msg = msg + ("[%s] %s" % (i, subj))
i += 1
j = 0
for test in tests[subj]:
msg = msg + ("\t[%s] %s" % (j, test))
j += 1
if __name__ == '__main__':
main()
main()