tweet.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os
4 import re
5 import sys
6 
7 import rospy
8 from std_msgs.msg import String
9 
10 from rostwitter.twitter import Twitter
11 from rostwitter.util import load_oauth_settings
12 
13 
14 class Tweet(object):
15  def __init__(self):
16  account_info = rospy.get_param(
17  'account_info', '/var/lib/robot/account.yaml')
18  ckey, csecret, akey, asecret = load_oauth_settings(account_info)
19  if not ckey or not csecret or not akey or not asecret:
20  sys.exit(1)
21 
22  self.api = Twitter(
23  consumer_key=ckey,
24  consumer_secret=csecret,
25  access_token_key=akey,
26  access_token_secret=asecret)
27  self.sub = rospy.Subscriber("tweet", String, self.tweet_cb)
28 
29  def tweet_cb(self, msg):
30  message = msg.data
31  # base64 messages are noisy, so tweet log is suppressed
32  rospy.loginfo(rospy.get_name() + " sending %s",
33  ''.join([message] if len(message) < 128 else message[0:128]+'......'))
34 
35  ret = self.api.post_update(message)
36  if ret is not None:
37  rospy.loginfo(rospy.get_name() + " receiving %s", ret)
38 
39 
40 if __name__ == '__main__':
41  rospy.init_node('rostwitter', anonymous=True)
42  app = Tweet()
43  rospy.spin()
def tweet_cb(self, msg)
Definition: tweet.py:29
def __init__(self)
Definition: tweet.py:15
def load_oauth_settings(yaml_path)
Definition: util.py:9


rostwitter
Author(s):
autogenerated on Sat Jun 24 2023 02:40:41