Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import json
- import random
- # pip install wykop-sdk
- import wykop
- def main():
- api = wykop.WykopAPI('APP_ID', 'APP_SEKRET')
- # id wpisu widoczny
- # tutaj
- # http://www.wykop.pl/wpis/22845879/mirki-i-mirabelki-%CA%96-zrobilem-generator-past-przy-/
- entry_id = os.environ['MIRKO_ENTRY_ID']
- entry = api.get_entry(entry_id)
- # wyciągam nicki plusujących
- voters = [item['author'] for item in entry['voters']]
- # mini baza danych ;)
- voters_answered_path = 'voters_answered.json'
- if not os.path.exists(voters_answered_path):
- with open(voters_answered_path, 'w') as fp:
- json.dump([], fp)
- voters_answered = []
- else:
- with open(voters_answered_path) as fp:
- voters_answered = json.load(fp)
- not_answered = list(set(voters) - set(voters_answered))
- print("Not answered:", not_answered)
- if not not_answered:
- return
- # Generowanie textu z sieci nauronowej
- sample = Sample()
- # wybieram jedną osobę z tych którym nie odpowiedziałem
- nick = random.choice(not_answered)
- reply = "@{author} Proszę bardzo ( ͡° ͜ʖ ͡°) \n\n{pasta}".format(
- author=nick,
- pasta=sample.generate()
- )
- api.authenticate('NICK', 'KLUCZPOLACZENIA')
- # Dodawanie komentarza
- api.add_entry_comment(entry_id, reply, None)
- print("API ADD ENTRY COMMENT:", entry_id, reply)
- voters_answered.append(nick)
- # aktualizuje listę, którym Mirkom odpowiedziałem
- with open(voters_answered_path, 'w') as fp:
- print("New voter added:", nick)
- json.dump(list(set(voters_answered)), fp)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement