@@ -27,7 +27,10 @@ def run(name, pswd, search_term):
27
27
gae_twitter = AppEngineTwitter (name , pswd )
28
28
results = gae_twitter .search (search_term .encode ('utf8' ), {'rpp' : 20 })
29
29
api = twitter .Api (username = bot_username , password = bot_password )
30
-
30
+ escape_user_list = []
31
+ escape_user_list .append (name )
32
+ escape_user_list .append ("milkcocoa" )
33
+
31
34
# Get most corrently tweeted tweet
32
35
status = api .GetUserTimeline ()
33
36
@@ -49,15 +52,34 @@ def run(name, pswd, search_term):
49
52
for i ,result in enumerate (results ):
50
53
rt = "RT @" + result ['from_user' ] + " " + result ['text' ]
51
54
rt_len = len (rt )
52
- if flag_enable and result ['from_user' ] != bot_username and rt_len < MAX_LEN :
55
+ if debug_flag :
56
+ print "[Debug] rt[" + str (i )+ "]: " + rt .encode ('utf8' )
57
+
58
+ if flag_enable :
59
+ print "I am going to tweet the tweet above."
60
+ if rt_len > MAX_LEN :
61
+ print "But, this tweet length is longer that 140 characters, so skipped it."
62
+ continue
63
+ if result ['from_user' ] in escape_user_list :
64
+ print "But, this tweet above is tweeted by Escape User, so skipped it."
65
+ continue
66
+ if result ['text' ].startswith ('@' ):
67
+ print "But, this tweet above starts with '@', so skipped it."
68
+ continue
53
69
"""
54
70
Retweet and exit
55
71
"""
56
- print "Re-tweet: " + rt .encode ('utf8' )
57
- print "Re-tweet Result: " + str (gae_twitter .update (rt .encode ('utf8' )))
72
+ if debug_flag :
73
+ print "Next Tweet: " + rt .encode ('utf8' )
74
+ else :
75
+ print "I have re-tweeted: " + rt .encode ('utf8' )
76
+ print "Result of my re-tweeting: " + str (gae_twitter .update (rt .encode ('utf8' )))
58
77
exit ()
59
78
60
79
if recent_tweet == rt :
80
+ if debug_flag :
81
+ print "My Most Recent Tweet: " + recent_tweet .encode ('utf8' )
82
+ print "-----------------------------------------------------"
61
83
flag_enable = 1
62
84
63
85
if flag_enable :
@@ -67,19 +89,37 @@ def run(name, pswd, search_term):
67
89
print "There are no tweets recently tweeted, so tweet the oldest tweet."
68
90
for i ,result in enumerate (results ):
69
91
rt = "RT @" + result ['from_user' ] + " " + result ['text' ]
70
- rt_len = len (rt )
71
- if result ['from_user' ] != bot_username and rt_len < MAX_LEN :
92
+ rt_len = len (rt )
93
+ if debug_flag :
94
+ print "[Debug] rt[" + str (i )+ "]: " + rt .encode ('utf8' )
95
+
96
+ if flag_enable :
97
+ print "I am going to tweet the tweet above."
98
+ if rt_len > MAX_LEN :
99
+ print "But, this tweet length is longer that 140 characters, so skipped it."
100
+ continue
101
+ if result ['from_user' ] in escape_user_list :
102
+ print "But, this tweet above is tweeted by Escape User, so skipped it."
103
+ continue
104
+ if result ['text' ].startswith ('@' ):
105
+ print "But, this tweet above starts with '@', so skipped it."
106
+ continue
72
107
"""
73
108
Retweet and exit
74
- """
75
- print "Re-tweet: " + rt .encode ('utf8' )
76
- print "Re-tweet Result: " + str (gae_twitter .update (rt .encode ('utf8' )))
109
+ """
110
+ if debug_flag :
111
+ print "Next Tweet: " + rt .encode ('utf8' )
112
+ else :
113
+ print "I have tweeted: " + rt .encode ('utf8' )
114
+ print "Result of my re-tweeting: " + str (gae_twitter .update (rt .encode ('utf8' )))
77
115
exit ()
78
116
79
117
# overriding API __init__
80
118
twitter .Api .__init__ = twitter_api_init_gae
81
119
82
120
# User Setting and Run Twitter Bot
121
+ debug_flag = True
122
+ #debug_flag = False
83
123
bot_username = 'CafeMiyamaBot'
84
124
bot_password = '???'
85
125
br = "<br>"
0 commit comments