Skip to content

Commit ebb7e10

Browse files
author
Yohei Yasukawa
committed
Add some exceptioin handlers.
1 parent e663500 commit ebb7e10

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

appengine_oauth.pyc

-3.96 KB
Binary file not shown.

appengine_twitter.pyc

-5.94 KB
Binary file not shown.

basehandler.pyc

-2.6 KB
Binary file not shown.

main.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ def run(name, pswd, search_term):
2727
gae_twitter = AppEngineTwitter(name, pswd)
2828
results = gae_twitter.search(search_term.encode('utf8'), {'rpp': 20})
2929
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+
3134
# Get most corrently tweeted tweet
3235
status = api.GetUserTimeline()
3336

@@ -49,15 +52,34 @@ def run(name, pswd, search_term):
4952
for i,result in enumerate(results):
5053
rt = "RT @" + result['from_user'] + " " + result['text']
5154
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
5369
"""
5470
Retweet and exit
5571
"""
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')))
5877
exit()
5978

6079
if recent_tweet == rt:
80+
if debug_flag:
81+
print "My Most Recent Tweet: " + recent_tweet.encode('utf8')
82+
print "-----------------------------------------------------"
6183
flag_enable = 1
6284

6385
if flag_enable:
@@ -67,19 +89,37 @@ def run(name, pswd, search_term):
6789
print "There are no tweets recently tweeted, so tweet the oldest tweet."
6890
for i,result in enumerate(results):
6991
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
72107
"""
73108
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')))
77115
exit()
78116

79117
# overriding API __init__
80118
twitter.Api.__init__ = twitter_api_init_gae
81119

82120
# User Setting and Run Twitter Bot
121+
debug_flag = True
122+
#debug_flag = False
83123
bot_username = 'CafeMiyamaBot'
84124
bot_password = '???'
85125
br = "<br>"

twitter.pyc

-71.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)