Guest User

Untitled

a guest
Sep 2nd, 2021
243
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import praw
  2. import os
  3. from time import sleep
  4. from gtts import gTTS
  5.  
  6. # You need to install gTTS and mpg321 on your machine
  7.  
  8. PORT = int(os.environ.get('PORT', 5000))
  9.  
  10. reddit = praw.Reddit(client_id='',
  11. client_secret='',
  12. user_agent='',
  13. username='',
  14. password='')
  15.  
  16. def __speak__(comment):
  17. if comment.author != 'AutoModerator':
  18. text = comment.body
  19. language = 'de' # todo automatically detect language
  20. myobj = gTTS(text=text, lang=language, slow=False)
  21. myobj.save("msw-comment.mp3")
  22. os.system("mpg321 msw-comment.mp3")
  23. os.remove("msw-comment.mp3")
  24. sleep(1)
  25.  
  26. #all comments
  27. def __readcomment__(comment_queue):
  28. # todo save first comment to not play it again
  29. while comment_queue:
  30. print('queue: ' + str(len(comment_queue)))
  31. comment = comment_queue.pop(0)
  32. __speak__(comment)
  33. if(len(comment.replies) > 0):
  34. print('comments: ' + str(len(comment.replies)))
  35. __readreplies__(comment.replies)
  36. print('comments up')
  37.  
  38. #through replies recursive
  39. def __readreplies__(replies):
  40. for reply in replies:
  41. __speak__(reply)
  42. if(len(reply.replies) > 0):
  43. __readreplies__(reply.replies)
  44.  
  45. sub = reddit.subreddit("mauerstrassenwetten")
  46. while True:
  47. for submissions in sub.hot(limit=4):
  48. if submissions.stickied:
  49. if ('Tägliche Diskussion ' in submissions.title) or ('Pläne ' in submissions.title):
  50. submissions.comment_sort = 'new'
  51. submissions.comments.replace_more(limit=20)
  52. comment_queue = submissions.comments[:]
  53. __readcomment__(comment_queue)
RAW Paste Data