Skip to content
Browse files

Bug fixes and functional modifications. Integrate Tweetbox into the m…

…ain program
  • Loading branch information...
1 parent a8f3f4c commit 63b32e12673b9e26ac31e64aad33a5aeb5b04166 @matburt committed Jul 1, 2009
Showing with 26 additions and 7 deletions.
  1. +4 −3 noaaRSS.py
  2. BIN stormTweet.sqlite
  3. +7 −0 stormtweet.py
  4. +6 −1 tweetBot.py
  5. +9 −3 tweetBox.py
View
7 noaaRSS.py
@@ -50,7 +50,8 @@ def parse(self, nfeed):
for e in nfeed['entries']:
## Only report the SevereThunderStormWarnings
- if e['id'].find('SevereThunderstormWarning') > 0:
+ if e['id'].find('SevereThunderstormWarning') > 0 \
+ or (e.has_key('summary') and e['summary'].find('THUNDERSTORM') > 0):
feedEntries.append(e)
newid = e['id'].split('=', 1)[1]
state = newid[0:2]
@@ -59,7 +60,7 @@ def parse(self, nfeed):
self.newEntries.append(newid)
self.shelf["thunderstorm"][newid] = state + ":" + \
e["summary"]
- self.displayEntry(e)
+ #self.displayEntry(e)
storm=self.recordEntry(e)
self.createAlert(storm)
self.shelf["thunderstorm"][newid]
@@ -104,7 +105,7 @@ def createAlert(self,storm):
peeps=peeps.filter_by(uState=storm.uState)
#record a tweet for every affected follower
for aPerson in peeps.all():
- print aPerson.name
+ print("Notifying: %s" % aPerson.name)
newTweet=Tweets(follower=aPerson,
storm=storm,tState=tState)
newTweet.save()
View
BIN stormTweet.sqlite
Binary file not shown.
View
7 stormtweet.py
@@ -3,6 +3,7 @@
import sys
import model
import tweetBot
+import tweetBox
from multiprocessing import Process
from ConfigParser import RawConfigParser
@@ -44,15 +45,21 @@ def main():
config.get("model", "bind"))
tb = tweetBot.TweetBot(config.get("tweetbox", "user"),
config.get("tweetbox", "password"))
+ tbox = tweetBox.TweetBox(config.get("tweetbox", "user"),
+ config.get("tweetbox", "password"),
+ config.get("model", "bind"))
tsProc = Process(target = ts.start)
tbProc = Process(target = tb.run)
+ tboxProc = Process(target = tbox.run)
tsProc.start()
tbProc.start()
+ tboxProc.start()
tsProc.join()
tbProc.join()
+ tboxProc.join()
if __name__ == '__main__':
main()
View
7 tweetBot.py
@@ -54,6 +54,7 @@ def recordMessage(self, message):
if not ustate:
self.tbox.direct_messages.new(user = sender,
text=SORRY_MSG % sender)
+ return
if action == 'follow':
fstate = FollowerStates.get_by(value='Active')
@@ -103,7 +104,11 @@ def makeFriends(self):
followers=set(self.tbox.followers.ids.stormwarn())
newFriends=followers - currentFriends
for aFriend in newFriends:
- self.tbox.friendships.create(id=aFriend)
+ try:
+ self.tbox.friendships.create(id=aFriend)
+ except Exception:
+ print "Failed to follow %s" % aFriend
+ continue
screen_name=self.tbox.users.show(id = aFriend)['screen_name']
self.tbox.direct_messages.new(user = screen_name,
text = FOLLOWING_MSG)
View
12 tweetBox.py
@@ -3,11 +3,11 @@
import sys
from ConfigParser import RawConfigParser
from model import *
+import time
class TweetBox:
def __init__(self, user, password, modelBind):
self.tbox=Twitter(user, password)
- setupModel(modelBind)
def stormMessage(self, message, receipient):
self.tbox.direct_messages.new(user=receipient,text=message)
@@ -33,6 +33,12 @@ def getAlerts(self):
t.update()
session.commit()
+ def run(self):
+ while True:
+ print("Sending alerts")
+ self.getAlerts()
+ time.sleep(5)
+
def getConfig(path):
rc = RawConfigParser()
if path not in rc.read(path):
@@ -57,11 +63,11 @@ def main():
sys.exit(1)
config = getConfig(options.config)
-
+ setupModel(config.get("model", "bind"))
tbox = TweetBox(config.get("tweetbox", "user"),
config.get("tweetbox", "password"),
config.get("model", "bind"))
- tbox.getAlerts()
+ tbox.run()
if __name__ == '__main__':
main()

0 comments on commit 63b32e1

Please sign in to comment.
Something went wrong with that request. Please try again.