Exemplo n.º 1
0
def main():

    # twitterから発言を取ってきてDBに格納する
    userdata = getAuthData(conf_path)
    tw = auth_api.connect(userdata["consumer_token"],
                          userdata["consumer_secret"], exec_path + "/common/")

    dbSession = model.startSession(userdata)

    page_number = 0
    update_flag = True
    while update_flag:
        update_flag = False
        l = tw.home_timeline(page=page_number)
        page_number += 1
        if page_number > 10: break
        for s in l:
            #if s.author.screen_name == userdata["user"]:continue
            jTime = s.created_at + datetime.timedelta(hours=9)
            name = unicode(s.user.screen_name)
            query = dbSession.query(model.Tweet).filter(
                and_(model.Tweet.datetime == jTime, model.Tweet.user == name))
            if (query.count() > 0): continue
            if (isNGUser(name)): continue
            update_flag = True

            t = model.Tweet()
            t.user = name
            t.text = s.text
            t.datetime = jTime
            t.replyID = s.in_reply_to_status_id
            t.tweetID = s.id
            #print "id:",s.id,
            dbSession.add(t)
            dbSession.commit()
Exemplo n.º 2
0
def sendMessage(str, reply_id):
    userdata = LoadUserData(conf_path)
    tw = auth_api.connect(userdata["consumer_token"], userdata["consumer_secret"], exec_path + "/common/")
    str = string.replace(str, "yystart", "")
    str = string.replace(str, "yyend", "")

    tw.update_status(str, reply_id)
Exemplo n.º 3
0
def sendMessage(str, reply_id):
    userdata = LoadUserData(conf_path)
    tw = auth_api.connect(userdata["consumer_token"],
        userdata["consumer_secret"], exec_path+"/common/")
    str = string.replace(str,'yystart','')
    str = string.replace(str,'yyend','')
    
    tw.update_status(str, reply_id)
Exemplo n.º 4
0
def main():
    #sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
    user = getAuthData(conf_path)
    session = model.startSession(user)

    api = auth_api.connect(user["consumer_token"], user["consumer_secret"])
    #api = tweepy_connect.connect()

    remove_at(session)
Exemplo n.º 5
0
def sendMessage(str,reply_id = -1):
    userdata = LoadUserData(conf_path)
    tw = auth_api.connect(userdata["consumer_token"],
        userdata["consumer_secret"], exec_path+"/common/")
    str = string.replace(str,'yystart','')
    str = string.replace(str,'yyend','')
    if g_debug :
        print(str)
    else:
        tw.update_status(str, reply_id)
Exemplo n.º 6
0
def main(str, newSession=None):
    global session
    sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
    #print "conf_path", conf_path
    user = getAuthData(conf_path)
    if session == None:
        if newSession == None:
            session = model.startSession(user)
        else:
            session = newSession
    api = auth_api.connect(user["consumer_token"], user["consumer_secret"],\
        common_path)
    #api = tweepy_connect.connect()
    return pickup_reply(str)
Exemplo n.º 7
0
def main(str, newSession=None):
    global session
    sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
    #print "conf_path", conf_path
    user = getAuthData(conf_path)
    if session == None:
        if newSession == None:
            session = model.startSession(user)
        else:
            session = newSession
    api = auth_api.connect(user["consumer_token"], user["consumer_secret"],\
        common_path)
    #api = tweepy_connect.connect()
    return pickup_reply(str)
Exemplo n.º 8
0
def sendMessage(str, reply_id):
    userdata = LoadUserData(conf_path)
    tw = auth_api.connect(userdata["consumer_token"],
        userdata["consumer_secret"], exec_path+"/common/")
    str = string.replace(str,'yystart','')
    str = string.replace(str,'yyend','')
    
    try:
        tw.update_status(str, reply_id)
    except TweepError,e:
        reg = re.compile('^\[{\'message\': \'(.+)\', \'code\': (\d+)}\]$')
        mat = reg.match(e.reason)
        if mat:
            code = mat.group(2)
            if code == '187':
                print 'status duplicate'
                return
        raise
Exemplo n.º 9
0
def main():

    # twitterから発言を取ってきてDBに格納する
    userdata = read_json(conf_path)
    g_ng_char = read_json(ng_char_path)
    tw = auth_api.connect(userdata["consumer_token"],
                          userdata["consumer_secret"], exec_path + "/common/")
    #print tw.rate_limit_status()
    dbSession = model.startSession(userdata)

    page_number = 0
    update_flag = True
    while update_flag:
        update_flag = False
        page_number += 1
        if page_number > 1: break

        #l = tw.home_timeline(page = page_number, count=10)
        #Toyko座標ベタ打ち
        woeid = tw.trends_closest(35.652832, 139.839478)[0]['woeid']
        trends_place = tw.trends_place(woeid)
        l = trends_place[0]['trends']
        for s in l:
            trend = s['name']
            if trend.startswith("#"): trend = trend[1:]
            #print(trend)
            update_flag = check_text(trend, dbSession)
            if (not (update_flag)): continue

            if (random.randint(0, 1)):
                text = "な、なによ……! ニコだって" + trend +\
                        "くらいできるんだから!!"
            else:
                text = trend + "と言えば?\nニコニー♪\nかわいい" +\
                        trend +"と言えば?\nニコニー♪"

            try:
                tw.update_status(text)
                print("trend " + trend)
            except tweepy.TweepError:
                pass
            #print("flag: ", update_flag)
            if update_flag: break
        dbSession.commit()
Exemplo n.º 10
0
def main():

    # twitterから発言を取ってきてDBに格納する
    userdata = getAuthData(conf_path)
    tw = auth_api.connect(userdata["consumer_token"],
        userdata["consumer_secret"], exec_path+"/common/")

    dbSession = model.startSession(userdata)

    page_number = 0
    update_flag = True
    while update_flag:
        update_flag = False
        l = tw.home_timeline(page = page_number, count=200)
        page_number += 1
        if page_number > 10: break
        for s in l:
            #if s.author.screen_name == userdata["user"]:continue
            jTime = s.created_at + datetime.timedelta(hours = 9)
            name = unicode(s.user.screen_name)
            query = dbSession.query(model.Tweet).filter(
                and_(model.Tweet.datetime== jTime, 
                        model.Tweet.user==name ))
            if( query.count() > 0 ): continue
            if( isNGUser(name) ): continue
            update_flag = True

            t = model.Tweet()
            t.user = name
            t.text = s.text
            t.datetime = jTime
            t.replyID = s.in_reply_to_status_id
            t.tweetID = s.id
            #print "id:",s.id, 
            dbSession.add(t)
            dbSession.commit()
    dbSession.close()