Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import json
- import vk_api
- from vk_api.longpoll import VkLongPoll, VkEventType
- candidate_names = {"Путин": 0, "Грудинин": 0, "Титов": 0, "Собчак": 0}
- def get_votes():
- with open('votes.txt', 'r') as file:
- json_text = file.read()
- global candidate_names
- candidate_names = json.loads(json_text)
- def main():
- vk_session = vk_api.VkApi(
- token='GOVNO JOPA')
- vk = vk_session.get_api()
- global candidate_names
- longpoll = VkLongPoll(vk_session)
- for event in longpoll.listen():
- if event.type == VkEventType.MESSAGE_NEW:
- if event.from_chat:
- if event.chat_id == 165 or event.chat_id == 133:
- for name in candidate_names:
- if ("+" + name).lower() == str(event.text).lower():
- candidate_names[name] += 1
- message_text = "У " + name + " уже " + str(candidate_names[name]) + " голосов"
- print(message_text)
- vk.messages.send(
- chat_id=event.chat_id,
- message=message_text
- )
- with open('votes.txt', 'w') as file:
- file.write(json.dumps(candidate_names))
- if __name__ == '__main__':
- get_votes()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement