Permalink
Browse files

Add methods to the twitterbot that can be overridden for welcome mess…

…ages.
  • Loading branch information...
1 parent 35d8ee9 commit df323c135571da62b26a2a2014aeecc6c4bb5133 @jverkoey committed Mar 30, 2009
Showing with 28 additions and 12 deletions.
  1. +0 −8 examplebot.py
  2. +28 −4 twitterbot.py
View
8 examplebot.py
@@ -42,11 +42,3 @@ def execute(self):
# Someone who isn't following us has sent us a reply.
print "I don't know this person: " + tweet.user.screen_name
-
- # We translate the db row into a user object for simplicity's sake.
- def dbToUser(self, row):
- return {
- 'id': row[0],
- 'screen_name': row[1],
- 'active': row[2],
- 'is_admin': row[3]}
View
32 twitterbot.py
@@ -69,6 +69,31 @@ def __init__(self, dbuser, dbpass, dbdb, twituser, twitpass):
self.updateUserLists()
+ '''Implement this function in your class to override
+ the message.
+ '''
+ def msgWelcomeNewUser(self, screen_name):
+ self.notifyUser(screen_name, "Thanks for following another 1-2-tweet bot! Find more at http://12tweet.com/")
+
+
+ '''Implement this function in your class to override
+ the message.
+ '''
+ def msgWelcomeBackUser(self, screen_name):
+ self.notifyUser(screen_name, "Welcome back! We've kept your profile safely tucked away")
+
+
+ '''Implement this function in your class if you have
+ other parameters stored in the user row.
+ '''
+ def dbToUser(self, row):
+ return {
+ 'id': row[0],
+ 'screen_name': row[1],
+ 'active': row[2],
+ 'is_admin': row[3]}
+
+
def updateUserLists(self):
################################
# Get all existing followers.
@@ -118,7 +143,7 @@ def updateUserLists(self):
if screen_name in self.disabled_users:
print "Reactivating " + screen_name
self.cursor.execute("UPDATE followers SET active=1 WHERE screen_name=%s", (screen_name))
- self.notifyUser(screen_name, "Welcome back! We've kept your profile safely tucked away")
+ self.msgWelcomeBackUser(screen_name)
user = self.disabled_users[screen_name]
del self.disabled_users[screen_name]
@@ -131,7 +156,7 @@ def updateUserLists(self):
row = self.cursor.fetchone()
user = self.dbToUser(row)
self.addExistingUser(user, user['screen_name'], user['active'])
- self.notifyUser(screen_name, "Thanks for following another 1-2-tweet bot! Find more at http://12tweet.com/")
+ self.msgWelcomeNewUser(user['screen_name'])
################################
@@ -145,7 +170,7 @@ def updateUserLists(self):
newly_deactivated[screen_name] = True
self.cursor.execute("UPDATE followers SET active=0 WHERE screen_name=%s", (screen_name))
# The user has stopped following us, so they won't even see this update.
- #notifyUser(screen_name, "Thanks for using findpassion!")
+ #notifyUser(screen_name, "Thanks for using another 1-2-tweet bot!")
# We move the users to the disabled map here because
# we can't remove elements from a map while traversing it
@@ -155,7 +180,6 @@ def updateUserLists(self):
self.disabled_users[screen_name] = user
-
def notifyUser(self, screen_name, message):
print "@"+screen_name+" "+message
self.api.PostUpdate("@"+screen_name+" "+message)

0 comments on commit df323c1

Please sign in to comment.