Advertisement
Guest User

GOVNO CODE

a guest
Mar 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import json
  4.  
  5. import vk_api
  6. from vk_api.longpoll import VkLongPoll, VkEventType
  7.  
  8. candidate_names = {"Путин": 0, "Грудинин": 0, "Титов": 0, "Собчак": 0}
  9.  
  10.  
  11. def get_votes():
  12.     with open('votes.txt', 'r') as file:
  13.         json_text = file.read()
  14.         global candidate_names
  15.         candidate_names = json.loads(json_text)
  16.  
  17.  
  18. def main():
  19.     vk_session = vk_api.VkApi(
  20.         token='GOVNO JOPA')
  21.     vk = vk_session.get_api()
  22.     global candidate_names
  23.     longpoll = VkLongPoll(vk_session)
  24.     for event in longpoll.listen():
  25.         if event.type == VkEventType.MESSAGE_NEW:
  26.             if event.from_chat:
  27.                 if event.chat_id == 165 or event.chat_id == 133:
  28.                     for name in candidate_names:
  29.                         if ("+" + name).lower() == str(event.text).lower():
  30.                             candidate_names[name] += 1
  31.                             message_text = "У " + name + " уже " + str(candidate_names[name]) + " голосов"
  32.                             print(message_text)
  33.                             vk.messages.send(
  34.                                 chat_id=event.chat_id,
  35.                                 message=message_text
  36.                             )
  37.                             with open('votes.txt', 'w') as file:
  38.                                 file.write(json.dumps(candidate_names))
  39.  
  40.  
  41. if __name__ == '__main__':
  42.     get_votes()
  43.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement