started tweet interaction

workspace
Brendan Howell 7 years ago
parent 582cfa1d49
commit 7d4f7ddace

@ -46,6 +46,26 @@ class PublicRelations(Bureau):
self.auth = twitter.OAuth(oauth_token, oauth_secret, CK, CS)
self.t.t = twitter.Twitter(auth=self.auth)
# setup DBs to map short codes to tweet ids
self.tweetdb = self.dbenv.open_db(b"tweetdb")
def get_tweet_id(self, tweet_hash):
"""
take a short code and look up the tweet id
"""
with self.dbenv.begin(db=self.tweetdb) as txn:
tweetid = txn.get(tweet_hash.encode())
return int(tweetid)
def short_tweet_id(self, tweet_id):
"""
take a tweet id and return a short alphanumeric code
"""
shortcode = ''.join(random.choice(string.ascii_letters + string.digits)
for _ in range(5)).encode()
with self.dbenv.begin(db=self.tweetdb, write=True) as txn:
txn.put(shortcode, msgid.encode())
@add_command("tweetpic", "Post a Document Camera Image to Twitter")
def tweet_pic(self):
"""
@ -74,7 +94,7 @@ class PublicRelations(Bureau):
# message='testing screenless post')
print("uploading photo " + photo)
graph.put_photo(image=open(photo, 'rb'), album_path=page_id + "/photos",
message='test photo')
message='#screenless')
#files = {"file": ("cam.jpg", open(photo, 'rb'))}
#args = {}
#args["access_token"] = access_token
@ -130,12 +150,51 @@ class PublicRelations(Bureau):
im.thumbnail((576, 576), PIL.Image.ANTIALIAS)
prn.image(im, impl="bitImageColumn")
tw_shortcode = self.short_tweet_id(t["id_str"])
prn.barcode("PRtwd." + hash_id, "CODE128", function_type="B")
prn.text("\r\n\r\n")
prn.cut()
@add_command("twd", "Print Tweet Details")
def tw_details(self, data):
"""
Print detailed tweet info and commands for reply, like, retweet, etc.
"""
tweet_id = self.get_tweet_id(data)
tweet = self.t.t.statuses.show(id=tweet_id)
# TODO: print tweet details
pass
@add_command("twrt", "Re-Tweet")
def tw_retweet(self, data):
"""
Re-Tweet a tweet from someone else.
"""
tweet_id = self.get_tweet_id(data)
self.t.t.statuses.retweet(id=tweet_id)
return
@add_command("twre", "Reply to Tweet")
def tw_reply(self, data):
"""
Reply to a tweet.
"""
# TODO: look up tweet id
#self.t.t.statuses.update(status="@AUTHOR_ID", media_ids=id_img1)
return
@add_command("twlk", "Like a Tweet")
def tw_like(self, data):
"""
'Like' a tweet.
"""
tweet_id = self.get_tweet_id(data)
self.t.t.favorites.create(id=tweet_id)
return
def main():
pr = PublicRelations()
pr.run()

Loading…
Cancel
Save