You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.1 KiB
Python

import twitter
from bureau import Bureau, add_command, add_api
class TWrapper():
pass
class PublicRelations(Bureau):
"""
The Public relations department manages the flow of information between
the screenless office and the general public. It provides interfaces
for Twitter, Facebook and other electronic PR platforms.
"""
name = "Public Relations"
prefix = "PR"
version = 0
def __init__(self):
Bureau.__init__(self)
self.auth = twitter.OAuth(
"423391766-bhjHwzD1eJfxB9s7ZvmeHReNVJM0d93kJ8KSrHEZ",
"qSvSYMs4lpSKbZtiuOjB1Gon5rzye8whvadcOdDpFocwa",
"arI4UCnfMeKZwAnyvJJIHVnUN",
"agrtzvh3eqSNlZpmPJZ0otclqSUjLKI3JrqugCPrp1Ch9dqsTl")
self.t = TWrapper()
self.t.t = twitter.Twitter(auth=self.auth)
@add_command("tweetpic", "Post a Document Camera Image to Twitter")
def tweet_pic(self):
"""
Takes a photograph using the document camera and posts it to Twitter.
"""
photo = self.send("PX", "photo")["photo"]
with open(photo, "rb") as imagefile:
imagedata = imagefile.read()
t_up = twitter.Twitter(domain='upload.twitter.com', auth=self.auth)
id_img1 = t_up.media.upload(media=imagedata)["media_id_string"]
self.t.t.statuses.update(status="#screenless", media_ids=id_img1)
@add_command("twtimeline", "Print Recent Tweets")
def tw_timeline(self, data=None):
"""
Print some recent tweets from your home timeline. Default is 10.
"""
if data:
try:
count = data["count"]
except KeyError as err:
print("You need to specify how many tweets you want!")
else:
count = 10
tweets = self.t.t.statuses.home_timeline(count=count)
out = ""
for t in tweets:
out += t["user"]["name"] + " : " + t["text"] + "\r\n\r\n"
self.print_small(out)
def main():
pr = PublicRelations()
pr.run()
if __name__ == "__main__":
main()