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.

51 lines
1.6 KiB
Python

import twitter
from bureau import Bureau, add_command, add_api
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)
@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.
"""
callback = self.prefix + "tweetpic_cb."
self.send("PXphoto.", {"callback": callback})
@add_api("tweetpic_cb", "callback for tweet_pic")
def tweetpic_cb(self, data):
"""
This does the actual uploading of the picture.
"""
photo = data["photo"]
auth = twitter.OAuth(
"423391766-bhjHwzD1eJfxB9s7ZvmeHReNVJM0d93kJ8KSrHEZ",
"qSvSYMs4lpSKbZtiuOjB1Gon5rzye8whvadcOdDpFocwa",
"arI4UCnfMeKZwAnyvJJIHVnUN",
"agrtzvh3eqSNlZpmPJZ0otclqSUjLKI3JrqugCPrp1Ch9dqsTl")
t = twitter.Twitter(auth=auth)
with open(photo, "rb") as imagefile:
imagedata = imagefile.read()
t_up = twitter.Twitter(domain='upload.twitter.com', auth=auth)
id_img1 = str(t_up.media.upload(media=imagedata)["media_id"])
t.statuses.update(status="PTT ★", media_ids=id_img1)
if __name__ == "__main__":
pr = PublicRelations()
pr.run()