Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. import os
  2. import json
  3. import random
  4.  
  5. # pip install wykop-sdk
  6. import wykop
  7.  
  8.  
  9. def main():
  10.     api = wykop.WykopAPI('APP_ID', 'APP_SEKRET')
  11.  
  12.     # id wpisu widoczny
  13.     #                           tutaj
  14.     # http://www.wykop.pl/wpis/22845879/mirki-i-mirabelki-%CA%96-zrobilem-generator-past-przy-/
  15.     entry_id = os.environ['MIRKO_ENTRY_ID']
  16.  
  17.     entry = api.get_entry(entry_id)
  18.    
  19.     # wyciągam nicki plusujących
  20.     voters = [item['author'] for item in entry['voters']]
  21.    
  22.     # mini baza danych ;)
  23.     voters_answered_path = 'voters_answered.json'
  24.  
  25.     if not os.path.exists(voters_answered_path):
  26.         with open(voters_answered_path, 'w') as fp:
  27.             json.dump([], fp)
  28.             voters_answered = []
  29.  
  30.     else:
  31.         with open(voters_answered_path) as fp:
  32.             voters_answered = json.load(fp)
  33.  
  34.     not_answered = list(set(voters) - set(voters_answered))
  35.     print("Not answered:", not_answered)
  36.  
  37.     if not not_answered:
  38.         return
  39.  
  40.     # Generowanie textu z sieci nauronowej
  41.     sample = Sample()
  42.  
  43.     # wybieram jedną osobę z tych którym nie odpowiedziałem
  44.     nick = random.choice(not_answered)
  45.     reply = "@{author} Proszę bardzo ( ͡° ͜ʖ ͡°) \n\n{pasta}".format(
  46.         author=nick,
  47.         pasta=sample.generate()
  48.     )
  49.  
  50.     api.authenticate('NICK', 'KLUCZPOLACZENIA')
  51.    
  52.     # Dodawanie komentarza
  53.     api.add_entry_comment(entry_id, reply, None)
  54.     print("API ADD ENTRY COMMENT:", entry_id, reply)
  55.     voters_answered.append(nick)
  56.    
  57.     # aktualizuje listę, którym Mirkom odpowiedziałem
  58.     with open(voters_answered_path, 'w') as fp:
  59.         print("New voter added:", nick)
  60.         json.dump(list(set(voters_answered)), fp)
  61.  
  62.  
  63. if __name__ == '__main__':
  64.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement