Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import soundcloud
- import pyttsx
- import praw
- import time
- import os
- class RobotTIFU(object):
- """Convert TIFU posts into a computerized voice"""
- def __init__(self):
- # self.reddit = rit.Reddit(user_agent='RobotTIFU')
- self.reddit = praw.Reddit(user_agent='RobotTIFU')
- self.reddit.login("robot_tifu",
- open("password").read()[:-1])
- # self.soundcloud = soundcloud.Client(
- # open("sc_clientid").read()[:-1],
- # open("sc_clientsecret").read()[:-1])
- def loop(self):
- """Runs periodically"""
- posts = self.reddit.get_subreddit("tifu").get_hot(limit=10)
- for post in posts:
- post = posts.next()
- with open("processed", "a") as output:
- output.write(post.title+"\n")
- # print post.title, ": ", post.selftext
- self.speak(post.selftext, post.id)
- # print post.selftext, "/tmp/"+post.id
- # post.add_comment('test_comment')
- # time.sleep(5)
- def run(self):
- """Initial running of the script"""
- while True:
- self.loop()
- time.sleep(5)
- @classmethod
- def speak(cls, string, filename):
- """Writes out the voice to filename"""
- with open("/tmp/sounds/"+filename, "wb") as output:
- output.write(string.encode("utf-8"))
- os.system("text2wave -o /tmp/sounds/"+filename+".wav /tmp/sounds/"+filename)
- TIFU = RobotTIFU()
- TIFU.loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement