Advertisement
Guest User

robot_tifu

a guest
Aug 11th, 2014
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. # import soundcloud
  2. import pyttsx
  3. import praw
  4. import time
  5. import os
  6. class RobotTIFU(object):
  7.     """Convert TIFU posts into a computerized voice"""
  8.     def __init__(self):
  9.         # self.reddit = rit.Reddit(user_agent='RobotTIFU')
  10.         self.reddit = praw.Reddit(user_agent='RobotTIFU')
  11.         self.reddit.login("robot_tifu",
  12.                 open("password").read()[:-1])
  13.         # self.soundcloud = soundcloud.Client(
  14.         #         open("sc_clientid").read()[:-1],
  15.         #         open("sc_clientsecret").read()[:-1])
  16.     def loop(self):
  17.         """Runs periodically"""
  18.         posts = self.reddit.get_subreddit("tifu").get_hot(limit=10)
  19.         for post in posts:
  20.             post = posts.next()
  21.             with open("processed", "a") as output:
  22.                 output.write(post.title+"\n")
  23.             # print post.title, ": ", post.selftext
  24.             self.speak(post.selftext, post.id)
  25.             # print post.selftext, "/tmp/"+post.id
  26.             # post.add_comment('test_comment')
  27.         # time.sleep(5)
  28.     def run(self):
  29.         """Initial running of the script"""
  30.         while True:
  31.             self.loop()
  32.             time.sleep(5)
  33.     @classmethod
  34.     def speak(cls, string, filename):
  35.         """Writes out the voice to filename"""
  36.         with open("/tmp/sounds/"+filename, "wb") as output:
  37.             output.write(string.encode("utf-8"))
  38.         os.system("text2wave -o /tmp/sounds/"+filename+".wav /tmp/sounds/"+filename)
  39. TIFU = RobotTIFU()
  40. TIFU.loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement