removed old callback style calls in PR and photo depts. add timeline print command to PR.

workspace
Brendan Howell 9 years ago
parent f55733eb3f
commit 40a645679d

@ -7,7 +7,7 @@ from bureau import Bureau, add_api
class Photography(Bureau):
"""
The Photography dept. provides document camera and other image
capture services for the Office.
capture services for other bureaus.
"""
name = "Photography Dept."
@ -18,23 +18,21 @@ class Photography(Bureau):
Bureau.__init__(self)
@add_api("photo", "Get Document Photo")
def print_fortune(self, data):
def photo(self):
"""
Takes a photograph using the document camera. Returns
the file name.
"""
try:
cb = data["callback"]
except KeyError as e:
print(e)
# TODO: this should log a real error
return
tmpimg = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False)
tmpimg.close()
cmd = "fswebcam --jpeg 95 --no-banner --resolution 1920x1080 -D 0.5 "
cmd += "-F 2 " + tmpimg.name
subprocess.check_output(cmd.split())
self.send(cb, {"photo": tmpimg.name})
# this is a dirty hack to keep the webcam system calls from hanging
cmd1 = "fswebcam --jpeg 95 --no-banner --resolution 320x240 /dev/null"
cmd2 = "fswebcam --jpeg 95 --no-banner --resolution 1920x1080 "
cmd2 += "-F 2 -S 1" + tmpimg.name
subprocess.check_output(cmd1.split())
subprocess.check_output(cmd2.split())
return {"photo": tmpimg.name}
if __name__ == "__main__":

@ -2,6 +2,8 @@ import twitter
from bureau import Bureau, add_command, add_api
class TWrapper():
pass
class PublicRelations(Bureau):
"""
@ -16,33 +18,45 @@ class PublicRelations(Bureau):
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.
"""
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)
photo = self.send("PX", "photo")["photo"]
with open(photo, "rb") as imagefile:
imagedata = imagefile.read()
t_up = twitter.Twitter(domain='upload.twitter.com', auth=auth)
t_up = twitter.Twitter(domain='upload.twitter.com', auth=self.auth)
id_img1 = str(t_up.media.upload(media=imagedata)["media_id"])
t.statuses.update(status="PTT ★", media_ids=id_img1)
self.t.t.statuses.update(status="#screenlessoffice ", 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)
if __name__ == "__main__":

Loading…
Cancel
Save