示例#1
0
def run(search_term):
    acc_token = pickle.load(file(KEY_FILE_API))
    gae_twitter = AppEngineTwitter()
    gae_twitter.set_oauth(CONSUMER_KEY, CONSUMER_SECRET, acc_token.key,
                          acc_token.secret)

    results = gae_twitter.search(search_term.encode('utf8'), {'rpp': 20})
    api = oauth_twitter(
    )  #twitter.Api(username=bot_username, password=bot_password)
    escape_user_list = []
    escape_user_list.append(BOT_USERNAME)

    # Get most corrently tweeted tweet
    status = api.GetUserTimeline()

    if debug_flag:
        print "Debugging..."
        hoge = api.GetReplies()
        for h in hoge:
            print h

    for s in status:
        if s.text.startswith("RT"):
            recent_tweet = s.text
            break
        else:
            print "The following tweet would be posted by hand, so skipped it."
            print "Tweet: " + s.text.encode('utf8')
            print

    print "Recent Tweet: " + recent_tweet.encode('utf8')
    print

    # Search Most Recent Tweet
    results.reverse()
    flag_enable = 0
    for i, result in enumerate(results):
        rt = "RT [at]" + result['from_user'] + " " + result['text']
        rt_len = len(rt)
        if debug_flag:
            print "[Debug] rt[" + str(i) + "]: " + rt.encode('utf8')

        if flag_enable:
            print "I am going to tweet the tweet above."
            if rt_len > MAX_LEN:
                print "But, this tweet length is longer that 140 characters, so skipped it."
                continue
            if result['from_user'] in escape_user_list:
                print "But, this tweet above is tweeted by Escape User, so skipped it."
                continue
            if result['text'].startswith('@'):
                print "But, this tweet above starts with '@', so skipped it."
                continue
            """
         Retweet and exit
         """
            if debug_flag:
                print "Next Tweet: " + rt.encode('utf8')
            else:
                print "I have re-tweeted: " + rt.encode('utf8')
                print "Result of my re-tweeting: " + str(
                    gae_twitter.update(rt.encode('utf8')))
            exit()

        if recent_tweet.replace("@", "[at]") == rt.replace("@", "[at]"):
            if debug_flag:
                print "My Most Recent Tweet: " + recent_tweet.encode('utf8')
                print "-----------------------------------------------------"
            flag_enable = 1

    if flag_enable:
        print "There are no tweet found that I should tweet."
        exit()
    print
    print "There are no tweets recently tweeted, so tweet the oldest tweet."
    print
    #   print "results: ",
    #   print str(results)
    for i, result in enumerate(results):
        rt = "RT [at]" + result['from_user'] + " " + result['text']
        rt_len = len(rt)
        if debug_flag:
            print "[Debug] rt[" + str(i) + "]: " + rt.encode('utf8')

        print "I am going to tweet the tweet above."
        if rt_len > MAX_LEN:
            print "But, this tweet length is longer that 140 characters, so skipped it."
            continue
        if result['from_user'] in escape_user_list:
            print "But, this tweet above is tweeted by Escape User, so skipped it."
            continue
        if result['text'].startswith('@'):
            print "But, this tweet above starts with '@', so skipped it."
            continue
        """
      Retweet and exit
      """
        if debug_flag:
            print "Next Tweet: " + rt.encode('utf8')
        else:
            print "I have tweeted: " + rt.encode('utf8')
            print "Result of my re-tweeting: " + str(
                gae_twitter.update(rt.encode('utf8')))
        exit()
示例#2
0
def run(name, pswd, search_term):
   acc_token = pickle.load(file(KEY_FILE_API))
   gae_twitter = AppEngineTwitter()   
   gae_twitter.set_oauth(OAUTH_KEY,
                         OAUTH_SECRET,
                         acc_token.key,
                         acc_token.secret)

   results = gae_twitter.search(search_term.encode('utf8'), {'rpp': 20})
   api = oauth_twitter() #twitter.Api(username=bot_username, password=bot_password)
   escape_user_list = []
   escape_user_list.append(name)
   escape_user_list.append("milkcocoa")
   escape_user_list.append("ikiben")
   
   # Get most corrently tweeted tweet
   status = api.GetUserTimeline()
   
   print "Debugging..."
   hoge = api.GetReplies()
   for h in hoge:
      print h
   
   for s in status:
      if s.text.startswith("RT"):
         recent_tweet = s.text
         break
      else:
         print "The following tweet would be posted by hand, so skipped it."
         print "Tweet: " + s.text.encode('utf8')
         print
      
   print "Recent Tweet: "+recent_tweet.encode('utf8')
   print

   # Search Most Recent Tweet
   results.reverse()
   flag_enable = 0
   for i,result in enumerate(results):
      rt = "RT [at]" + result['from_user']  + " " + result['text']
      rt_len = len(rt)
      if debug_flag:
         print "[Debug] rt["+str(i)+"]: " + rt.encode('utf8') 
      
      if flag_enable:
         print "I am going to tweet the tweet above."
         if rt_len > MAX_LEN:
            print "But, this tweet length is longer that 140 characters, so skipped it."
            continue
         if result['from_user'] in escape_user_list:
            print "But, this tweet above is tweeted by Escape User, so skipped it."
            continue
         if result['text'].startswith('@'):
            print "But, this tweet above starts with '@', so skipped it."
            continue
         """
         Retweet and exit
         """
         if debug_flag:
            print "Next Tweet: "+rt.encode('utf8')
         else:
            print "I have re-tweeted: "+rt.encode('utf8')
            print "Result of my re-tweeting: " + str(gae_twitter.update(rt.encode('utf8')))
         exit()
               
      if recent_tweet.replace("@", "[at]") == rt.replace("@", "[at]"):
         if debug_flag:
            print "My Most Recent Tweet: " + recent_tweet.encode('utf8')
            print "-----------------------------------------------------"
         flag_enable = 1

   if flag_enable:
      print "There are no tweet found that I should tweet."
      exit()
   print
   print "There are no tweets recently tweeted, so tweet the oldest tweet."
   print
#   print "results: ",
#   print str(results)
   for i,result in enumerate(results):  
      rt = "RT [at]" + result['from_user']  + " " + result['text']  
      rt_len = len(rt)
      if debug_flag:
         print "[Debug] rt["+str(i)+"]: " + rt.encode('utf8') 

      print "I am going to tweet the tweet above."
      if rt_len > MAX_LEN:
         print "But, this tweet length is longer that 140 characters, so skipped it."
         continue
      if result['from_user'] in escape_user_list:
         print "But, this tweet above is tweeted by Escape User, so skipped it."
         continue
      if result['text'].startswith('@'):
         print "But, this tweet above starts with '@', so skipped it."
         continue
      """
      Retweet and exit
      """
      if debug_flag:
         print "Next Tweet: "+rt.encode('utf8')
      else:
         print "I have tweeted: "+rt.encode('utf8')
         print "Result of my re-tweeting: " + str(gae_twitter.update(rt.encode('utf8')))
      exit()