Example #1
0
 def setUp(self):
   self.db = IfGovDb()
   self.db.removeSubscriptionByName('jamestest')
   self.db.insertSubscription('jamestest', 0, 0, 1, 1, None, 1, '*****@*****.**', '20140101', '0', '20140713', '1', '20140712', False)
Example #2
0
#!/usr/bin/python

from ifgovdb import IfGovDb
from mail import Mailer
import logging
from datetime import datetime

logging.basicConfig(filename='/home/bitnami/ifsubthenemail/ifgov.log', level=logging.INFO)
logging.info("Started at " + str(datetime.now()))

mailer = Mailer()
db = IfGovDb()

for s in db.getNewSubscriptions():
  if s.notificationsettings != None:
    address = s.notificationsettings
    message = "You have registered a new notification with ifGov.  If at (" + str(s.lon) + "," + str(s.lat) + ") when " + s.source + " is changed then email me." 
    logging.info("Emailing " + address + ": " + message)
    mailer.sendMail([address],"*****@*****.**","New Subscription",message);
    db.setWelcomed(s)
  else:
    logging.warn("No email address for " + s.name)

for s in db.getChangedSubscriptions():
  if s.notificationsettings != None:
    address = s.notificationsettings
    message = s.source + " was " + s.lastvalue + " and is now " + s.currentvalue + "."
    logging.info("Emailing " + address + ": " + message)
    mailer.sendMail([address],"*****@*****.**","Changed value",message);
    db.setNotified(s)
  else:
Example #3
0
class TestSequenceFunctions(unittest.TestCase):
  def setUp(self):
    self.db = IfGovDb()
    self.db.removeSubscriptionByName('jamestest')
    self.db.insertSubscription('jamestest', 0, 0, 1, 1, None, 1, '*****@*****.**', '20140101', '0', '20140713', '1', '20140712', False)
    
  def tearDown(self):
    self.db.removeSubscriptionByName('jamestest')
    
  def test_getSubscriptionByName(self):
    sub = self.db.getSubscriptionByName('jamestest')
    self.assertEquals('jamestest', sub.name)
  
  def test_getNewSubscriptions(self):
    subs = self.db.getNewSubscriptions()
    self.assertTrue(len(subs) > 0)
    for sub in subs:
      if sub.name == 'jamestest':
        self.assertEquals('*****@*****.**', sub.notificationsettings)
        
  def test_getChangedSubscriptions(self):
    subs = self.db.getChangedSubscriptions()
    for sub in subs:
      self.assertTrue(sub.lastnotified < sub.currentupdate)
        
  def test_setNotified(self):
    starttime = datetime.now()
    sub = self.db.getSubscriptionByName('jamestest')
    self.db.setNotified(sub)
    sub = self.db.getSubscriptionByName('jamestest')
    self.assertTrue(sub.lastnotified > starttime)