Exemple #1
0
def create_api(atoken = '', asecret = '', auth = None):
	u"""
	APIオブジェクトを作る
	"""
	keys = ApiKeys.objects.get()
	ckey = keys.ckey.encode('utf-8')
	csecret = keys.csecret.encode('utf-8')
	print(ckey, csecret)
	if isinstance(auth, models.Authorization):
		return twoauth.api(ckey, csecret, auth.token, auth.token_secret)
	else:
		return twoauth.api(ckey, csecret, atoken, asecret)
Exemple #2
0
def create_api(request):
    from models import Authorization

    user_id = request.session["user_id"]
    auth = Authorization.objects.get(user_id=user_id)
    (ckey, csecret) = get_consumers()
    return twoauth.api(ckey, csecret, auth.token, auth.token_secret)
Exemple #3
0
    def __init__(self, user):
        self.user = user
        login = Pit.get(self.user)
        self.ckey = login["ckey"]
        self.csecret = login["csecret"]
        self.atoken = login["atoken"]
        self.asecret = login["asecret"]

        self.api = twoauth.api(self.ckey, self.csecret, self.atoken, self.asecret)
Exemple #4
0
 def get(self):
     datas = Tweet.gql("ORDER BY tweet_id ASC")
     self.response.out.write("Hello!<br>")
     tw = None
     if datas:
         try:
             tw = twoauth.api(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SERCRET)
         except Exception, e:
             text = str(e)
             self.response.out.write(text+"<br><br>")
             return
Exemple #5
0
    def __init__(self, keys, maxn=20):
        # Generate API Library instance
        self.api = twoauth.api(*keys)
        #        self.api.initialize()
        self.threads = list()

        # User, Status Buffer
        self.users = dict()
        self.statuses = dict()

        self.maxn = maxn
        self.my_name = keys[-1]
Exemple #6
0
 def __init__(self):
     self.BASE_DIR = os.path.dirname(os.path.abspath(__file__))
     self.inifile = os.path.join(self.BASE_DIR, 'settings.ini')
     self.t_ini = self._load_ini('twitter')
     self.m_ini = self._load_ini('markov')
     self.m = markovchains.MarkovChains(int(self.m_ini['num']))
     self.m.load_db('mysql', self.m_ini['db'])
     self.api = twoauth.api(
                        self.t_ini['consumer_key'],
                        self.t_ini['consumer_secret'],
                        self.t_ini['access_token'],
                        self.t_ini['access_token_secret'])
     self.log = twilog.Twilog()
     self.reply = ""
     self.url = ""
Exemple #7
0
    def __init__(self, ckey, csecret, atoken, asecret, screen_name):
        locale.setlocale(locale.LC_ALL, "")

        # twitter api instance
        self.api = twoauth.api(
            ckey, csecret, atoken, asecret, screen_name)
        self.userlastget = datetime.datetime.min
        self.listed = -1
        
        # init temporary stack
        self.tmp = list()
        self.hist = list()

        self.statusfooter = u""
        self.autoreload = 60000 # ms
Exemple #8
0
    def __init__(self):
        key,secret = self.load_auth()
        self.api = twoauth.api(CONSUMER_KEY,CONSUMER_SECRET,key,secret)
        self.me = self.api.verify_credentials()
        self.my_name = self.me.screen_name
        pynotify.init("Silfatter")
        self.statuses = {}

        self.iconstore = IconStore()
        self.reply_getter = InReplyGetter(self)
        self.twtool = twittertool.TwitterTool()

        self.window = ClientWindow()

        self.accelgroup = gtk.AccelGroup()
        self.window.add_accel_group(self.accelgroup)
        stream = StreamingThread(self)
        rest = RestThread(self)

        main_vbox = gtk.VBox()

        self.lines_note_book = gtk.Notebook()
        self.home_timeline_sw = Timelinesw(self,"home")
        self.mention_timeline_sw = Timelinesw(self,"mention")
        self.event_timeline_sw = Eventlinesw(self)

        stream.add_timeline(self.home_timeline_sw.view)
        stream.add_timeline(self.mention_timeline_sw.view)
        stream.add_eventline(self.event_timeline_sw.view)

        rest.add(self.home_timeline_sw.view)
        rest.add(self.mention_timeline_sw.view)

        self.post_window = PostWindow(self)
        self.url_window = UrlWindow(self)

        self.lines_note_book.append_page(self.home_timeline_sw,gtk.Label("Home"))
        self.lines_note_book.append_page(self.mention_timeline_sw,gtk.Label("Mention"))
        self.lines_note_book.append_page(self.event_timeline_sw,gtk.Label("Event"))

        self.window.add(main_vbox)
        self.window.set_size_request(300,300)

        main_vbox.pack_start(self.lines_note_book,expand=True,fill=True)

        stream.start()
        rest.start()
        self.window.show_all()
Exemple #9
0
 def __init__(self, access_key, access_secret, screen_name):
   self.access_key = access_key
   self.access_secret = access_secret
   self.oauth=twoauth.oauth('fhGWsi5X64CCGzJ7LjI9Sw',
                            'jANLXQFGVIK0qYaCfbAIziHZXfdcg6g3pGLHOkU0',
                            self.access_key,
                            self.access_secret)
   self.api=twoauth.api('fhGWsi5X64CCGzJ7LjI9Sw',
                        'jANLXQFGVIK0qYaCfbAIziHZXfdcg6g3pGLHOkU0',
                        self.access_key,
                        self.access_secret)
   self.screen_name = screen_name
   self.verbose = True
   self.sending = threading.RLock()
   self.friends = []
   signal.signal(signal.SIGTERM, self.stop)
Exemple #10
0
 def __init__(self, screen_name, ckey, csecret, atoken, asecret):
     # set timeout
     socket.setdefaulttimeout(90)
     
     # Generate API Library instance
     self.api = twoauth.api(ckey, csecret, atoken, asecret, screen_name)
     self.sapi = twoauth.streaming.StreamingAPI(self.api.oauth)
     
     self._my_id = -1
     self.my_name = screen_name
     
     self.apilock = threading.Lock()
     
     # User, Status Buffer
     self.users = dict()
     self.screen_name = dict()
     self.statuses = dict()
     self.followers = set()
     self.following = set()
     self.configuration = dict()
     self.hashtags = set()
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import sys
import twoauth

if __name__ == "__main__":
    ckey = sys.argv[1]
    csecret = sys.argv[2]
    atoken = sys.argv[3]
    asecret = sys.argv[4]
    
    api = twoauth.api(
        ckey, csecret, atoken, asecret)
    
    friends = api.friends_ids()
    followers = api.followers_ids()
    
    fr = list()
    fo = list()

    for u in friends:
        fr.append(long(u))
    for u in followers:
        fo.append(long(u))
    
    for u in sorted(fr):
        if u in fo:
            fo.remove(u)
            print "<>", u
        else:
Exemple #12
0
#!/usr/bin/env python

import twoauth
import roslib; roslib.load_manifest('rostwitter')
import rospy
from std_msgs.msg import String

consumer_key = 'feliLoH9Zlp6hfxO8jhEA'
consumer_secret = 'OtVjrXVezSMxVJrf99HlfTr2fsHQxcEJaAPdxfStkA'
access_token = '4416471-cKU7HJPDnQt5yAZ98zbhSertqhSyLFSnntX1EQhbaw'
access_token_secret = 'S68gl5qK11gIYAhRSnkDLJQQUy4I2Goei3tUVg5F0E'

def twit(data):
    rospy.loginfo(rospy.get_name()+"I heard %s",data.data)
    twitter.status_update(data.data)

def listener():
    rospy.init_node('rostwit_server', anonymous=True)
    rospy.Subscriber("twit", String, twit)
    rospy.spin()

if __name__ == '__main__':
    twitter = twoauth.api(consumer_key, consumer_secret, access_token, access_token_secret)
    listener()


Exemple #13
0
#!/usr/bin/env python

import twoauth
import roslib
roslib.load_manifest('rostwitter')
import rospy
from std_msgs.msg import String

consumer_key = 'feliLoH9Zlp6hfxO8jhEA'
consumer_secret = 'OtVjrXVezSMxVJrf99HlfTr2fsHQxcEJaAPdxfStkA'
access_token = '4416471-cKU7HJPDnQt5yAZ98zbhSertqhSyLFSnntX1EQhbaw'
access_token_secret = 'S68gl5qK11gIYAhRSnkDLJQQUy4I2Goei3tUVg5F0E'


def twit(data):
    rospy.loginfo(rospy.get_name() + "I heard %s", data.data)
    twitter.status_update(data.data)


def listener():
    rospy.init_node('rostwit_server', anonymous=True)
    rospy.Subscriber("twit", String, twit)
    rospy.spin()


if __name__ == '__main__':
    twitter = twoauth.api(consumer_key, consumer_secret, access_token,
                          access_token_secret)
    listener()
Exemple #14
0
import simplejson
import cPickle as pickle
import codecs
import sys
import os
import itertools
from pymecab.pymecab import PyMecab

baseURI = "http://twitter.com/statuses/"

import twoauth
#################################
## initialize oauth
#################################
twitterapi = twoauth.api(os.environ["TWITTER_CONSUMER_KEY"],
                         os.environ["TWITTER_CONSUMER_SECRET"],
                         os.environ["TWITTER_ACCESS_KEY"],
                         os.environ["TWITTER_ACCESS_SECRET"])


###################################################
##       Post Twit
###################################################
def post_twit(par):
    dto = socket.getdefaulttimeout()
    socket.setdefaulttimeout(6)
    url = baseURI
    postData = {}
    postData["status"] = par
    postData["source"] = "douyo"
    params = "status=" + urllib.quote(postData["status"].encode("utf-8")) + "&"
    params = params + ("source=" + postData["source"])
Exemple #15
0
def load_oauth_settings():
    # see http://d.hatena.ne.jp/gumilab/20101004/1286154912 to setup CKEY/AKEY
    try:
        key = yaml.load(open('/var/lib/robot/twitter_account_pr2jsk.yaml'))
        global CKEY, CSECRET, AKEY, ASECRET
        CKEY = key['CKEY']
        CSECRET = key['CSECRET']
        AKEY = key['AKEY']
        ASECRET = key['ASECRET']
    except IOError as e:
        rospy.logerr('"/var/lib/robot/twitter_account_pr2jsk.yaml" not found')
        rospy.logerr("$ rosrun python_twoauth get_access_token.py")
        rospy.logerr("cat /var/lib/robot/twitter_account_pr2jsk.yaml <<EOF")
        rospy.logerr("CKEY: xxx")
        rospy.logerr("CSECRET: xxx")
        rospy.logerr("AKEY: xxx")
        rospy.logerr("ASECRET: xxx")
        rospy.logerr("EOF")
        rospy.logerr(
            'see http://d.hatena.ne.jp/gumilab/20101004/1286154912 for detail')
        sys.exit(-1)


if __name__ == '__main__':
    rospy.init_node('rostwitter', anonymous=True)
    load_oauth_settings()
    twitter = twoauth.api(CKEY, CSECRET, AKEY, ASECRET)
    rospy.Subscriber("pr2twit", String, twit)
    rospy.spin()
Exemple #16
0
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import twoauth

if __name__ == "__main__":
    import sys
    
    api = twoauth.api(
        sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])

    timeline = True
    status = False
    user = False
    lists = False
    dm = False
    friendship = False
    account = False
    favorites = False
    block = False
    
    print "screen_name:", api.user["screen_name"]

    if timeline:
        print "Timeline:"
        for tl in (api.public_timeline(),
                   api.home_timeline(),
                   api.friends_timeline(),
                   api.user_timeline(),
                   api.mentions(),
                   api.rt_by_me(),
Exemple #17
0
    ##twitter.status_update(message)
    return

def load_oauth_settings():
# see http://d.hatena.ne.jp/gumilab/20101004/1286154912 to setup CKEY/AKEY
    try:
        key = yaml.load(open('/var/lib/robot/twitter_account_pr2jsk.yaml'))
        global CKEY, CSECRET, AKEY, ASECRET
        CKEY = key['CKEY']
        CSECRET = key['CSECRET']
        AKEY = key['AKEY']
        ASECRET = key['ASECRET']
    except IOError as e:
        rospy.logerr('"/var/lib/robot/twitter_account_pr2jsk.yaml" not found')
        rospy.logerr("$ rosrun python_twoauth get_access_token.py")
        rospy.logerr("cat /var/lib/robot/twitter_account_pr2jsk.yaml <<EOF")
        rospy.logerr("CKEY: xxx")
        rospy.logerr("CSECRET: xxx")
        rospy.logerr("AKEY: xxx")
        rospy.logerr("ASECRET: xxx")
        rospy.logerr("EOF")
        rospy.logerr('see http://d.hatena.ne.jp/gumilab/20101004/1286154912 for detail')
        sys.exit(-1)

if __name__ == '__main__':
    rospy.init_node('rostwitter', anonymous=True)
    load_oauth_settings()
    twitter = twoauth.api(CKEY, CSECRET, AKEY, ASECRET)
    rospy.Subscriber("pr2twit", String, twit)
    rospy.spin()