Advertisement
Guest User

Untitled

a guest
Mar 12th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.05 KB | None | 0 0
  1. from vk_api.longpoll import VkLongPoll, VkEventType
  2. import vk_api
  3. import requests
  4. from lxml import html
  5. print('Математика - 1')
  6. print('Информатика - 2')  # вывод в одном сообщении через новый абзац
  7.  
  8.  
  9. login, password = "+79995640123","T8y9l5e3r"
  10.  
  11. token = "a238249ac1f75e1b9db6bdd434b69c690247f4011284e37d173fe6cccee0ee0fa15e30430223411b2f558"
  12. vk_session = vk_api.VkApi(token=token)
  13.  
  14. session_api = vk_session.get_api()
  15. longpoll = VkLongPoll(vk_session)
  16.  
  17. while True:
  18.     for event in longpoll.listen():
  19.         if event.type == VkEventType.MESSAGE_NEW:
  20.             men = int()
  21.             real = int()
  22.             response = str(event.text.lower())
  23.             if event.from_user :
  24.                 if response == "help":
  25.                     vk_session.method('messages.send',{'user_id': event.user_id, 'message': 'ВВедите предмет и тд, заебал ты, если честно!', 'random_id': 0})
  26.             if event.from_user:
  27.                 if response == "math":
  28.                     subject = 1
  29.             if event.from_user:
  30.                 if men == 1:
  31.                     ex = 1
  32.             if event.from_user:
  33.                 if men == 1:
  34.                     count = 1
  35.  
  36.                     task_p = ''
  37.                     k = 0
  38.  
  39.                     subj = {
  40.                         '1': 'math',  # проверить на всех заданиях
  41.                         '2': 'inf',
  42.                         'Русский': 'rus'  # не готов
  43.                     }
  44.  
  45.                     params = {
  46.                         ('prob' + ex): count,
  47.                         'public': False
  48.                     }
  49.  
  50.                     inv = {
  51.                         '\xad': '',
  52.                         '\xa0': ''
  53.                     }
  54.  
  55.                     url = 'https://' + subj[subject] + 'ege.sdamgia.ru'
  56.                     session = requests.session()
  57.                     r = session.post(url + '/test?a=generate', params)
  58.                     tree = html.fromstring(r.text)
  59.                     choice = tree.xpath('//div[@class = "new_header"]/b/text()')
  60.                     choice = choice[0]
  61.                     choice = choice[10::]
  62.                     prob = tree.xpath('//div[@class = "prob_maindiv"]')
  63.  
  64.                     for i in prob:
  65.                         pro = prob[k].attrib['id']
  66.                         pro = pro[7::]
  67.                         k += 1
  68.                         params = {
  69.                             'a': 'check',
  70.                             ('answer_' + str(k) + '_' + str(pro)): '',
  71.                             'is_cr': 1,
  72.                             'stat_id': 0,
  73.                             'test_id': choice,
  74.                             'timer': 1
  75.                         }
  76.                         r = session.post(url + '/test', params)
  77.                         tree = html.fromstring(r.text)
  78.                         t_answ = tree.xpath('//td[5]/text()')
  79.                         task = tree.xpath('//div[@class="pbody"][1]/p/text()')
  80.                         try:
  81.                             img = tree.xpath('//p/img/@src')[0]
  82.                             img = url + img
  83.                         except Exception:
  84.                             img = ''
  85.                         for i in task:
  86.                             task_p += i
  87.                         for i in inv:
  88.                             n = task_p.count(i)
  89.                             task_p = task_p.replace(i, '', n)
  90.                         print(task_p)  # Вывод задания
  91.                         print(img)
  92.                         answ = input('Введите ответ: ')
  93.                         if t_answ[0] == answ:
  94.                             print('Верно, ответ: ', answ)
  95.                         else:
  96.                             print('Неверно')
  97.  
  98.                 elif response == "пока":
  99.                     vk_session.method('messages.send', {'user_id': event.user_id, 'message': 'Пока, друг!', 'random_id': 0})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement