def test_add(self): self.subscribers.add('*****@*****.**') self.subscribers.add('*****@*****.**') with self.assertRaises(Exception): self.subscribers.add('*****@*****.**') s = Subscribers() with self.assertRaises(Exception): s.add('*****@*****.**') s.add('*****@*****.**') with self.assertRaises(Exception): s.add('*****@*****.**')
response = urllib.urlopen( 'http://www.haifa-stadium.co.il/%D7%9E%D7%A9%D7%97%D7%A7%D7%99_%D7%9B%D7%93%D7%95%D7%A8%D7%92%D7%9C' ) data = response.read() parser.feed(data) games = parser.table have_game_today = False time = 0 for game in games: day, month = game['date'].split('/', 1) if day == str(datetime.now().day) and month == str(datetime.now().month): have_game_today = True time = game['time'] break if have_game_today: mail = GmailWrapper() mail.get_credentials() credentials = mail.get_credentials() http = credentials.authorize(httplib2.Http()) service = discovery.build('gmail', 'v1', http=http) s = Subscribers() for email in s.subscribers: msg = mail.create_mail( '*****@*****.**', email, 'Game today', 'Unfortunately there\'s a game today in Sami Ofer stadium, starting at ' + str(time) + ', so beware of traffic!') mail.send_message(service, 'me', msg)
import sys from Subscribers import Subscribers if len(sys.argv) < 2: sys.exit('Usage: {0} e-mail'.format(sys.argv[0])) s = Subscribers() try: s.add(sys.argv[1]) except Exception as e: sys.exit(e.message) print 'Registration succeeded!'
return self.send_to_subscribers(log.get_type()) self._log_count[log.get_type()]['first_occurence'] = None self._log_count[ log.get_type()]['wait_until'] = log.get_time() + wait_time self._log_count[log.get_type()]['count'] = 0 def execute_leftover(self): for log_type, log_info in self._log_count.items(): if log_info['count'] == self._config[log_type]['frequency']: self.send_to_subscribers(log_type) def send_to_subscribers(self, log_type): print(log_type, end=':\n') for subscriber in self._subscribers.get_subscribers_of_log_type( log_type): print('-', subscriber.get_name()) print() if __name__ == '__main__': subscribers = Subscribers() subscribers.add_subscriber(Person('Adi'), ['info']) subscribers.add_subscriber(Person('Kumar'), ['info', 'critical', 'warning']) subscribers.add_subscriber(Person('Gilang'), ['critical']) driver = Driver('input.txt', subscribers) driver.run_through_log()
def __init__(self, *args, **kwargs): super(TestSubscribers, self).__init__(*args, **kwargs) if os.path.exists('subscribers') and os.path.isfile('subscribers'): os.remove('subscribers') self.subscribers = Subscribers()
class TestSubscribers(unittest.TestCase): def __init__(self, *args, **kwargs): super(TestSubscribers, self).__init__(*args, **kwargs) if os.path.exists('subscribers') and os.path.isfile('subscribers'): os.remove('subscribers') self.subscribers = Subscribers() def test_check_if_email(self): self.subscribers.__check_if_email__('*****@*****.**') with self.assertRaises(ValueError): self.subscribers.__check_if_email__('Hello world!') with self.assertRaises(ValueError): self.subscribers.__check_if_email__('a@b') with self.assertRaises(ValueError): self.subscribers.__check_if_email__('@.com') with self.assertRaises(ValueError): self.subscribers.__check_if_email__(42) def test_add(self): self.subscribers.add('*****@*****.**') self.subscribers.add('*****@*****.**') with self.assertRaises(Exception): self.subscribers.add('*****@*****.**') s = Subscribers() with self.assertRaises(Exception): s.add('*****@*****.**') s.add('*****@*****.**') with self.assertRaises(Exception): s.add('*****@*****.**')