def add_event(bot, update): typing(bot, update) global some_event if status["add_event"] == 0: status["add_event"] = 4 message = "adding event to a friend 😉" bot.send_message(chat_id=update.message.chat_id, text=message) message = "Please enter your friend's name: " bot.send_message(chat_id=update.message.chat_id, text=message) status["add_event"] -= 1 some_event.append(update.message.chat_id) elif status["add_event"] == 3: name = update.message.text c = Client(settings.HOST, settings.DB) flag = False for friend in c.get_all_friends(update.message.chat_id): if friend['full_name'] == name: flag = True if flag: some_event.append(name) message = "Enter Event Type:" bot.send_message(chat_id=update.message.chat_id, text=message) status["add_event"] -= 1 else: status["add_event"] = 0 some_event = [] message = " 🤔 your friend doesn't exist in the list. add him by /add_friend" bot.send_message(chat_id=update.message.chat_id, text=message) elif status["add_event"] == 2: type = update.message.text some_event.append(type) message = "Enter event Date <yyyy/mm/dd>: " bot.send_message(chat_id=update.message.chat_id, text=message) status["add_event"] -= 1 elif status["add_event"] == 1: date = update.message.text date = date.split('/') date = [int(d) for d in date] date = datetime.datetime(*date) some_event.append(date) some_event.append(False) e = Event(settings.HOST, settings.DB) e.add_event(*some_event) message = f"YAY you added an event to {some_event[1]} 😊" bot.send_message(chat_id=update.message.chat_id, text=message) send_notification(bot, update, some_event) some_event = [] status["add_event"] -= 1
def create_list_events(n): # For the following tests, you must specify an even number # to generate the same number of suitable and unsuitable results for i in range(n): day = randint(1, 5) if i % 2 == 0 else randint(15, 30) yield Event( event_id=str(uuid.uuid4()), service=TestDynamoDBCreateTableAndFillCase.get_random_services(), start_time=parser.parse("Mar {0} 00:00:00 PST 2018".format(day)), end_time=parser.parse("Mar {0} 15:00:00 PST 2018".format(day)) )
def show_upcoming_events(bot, update): typing(bot, update) message = "Upcoming Events ➙ \n" e = Event(settings.HOST, settings.DB) events = e.get_all_events() upcoming_events = [] for event in events: d0 = datetime.datetime.now() d1 = datetime.datetime(d0.year, event['date'].month, event['date'].day) delta = d1 - d0 if delta.days < 10: upcoming_events.append(event) for u_event in upcoming_events: if delta.days == 0: message += f"{u_event['name']} {u_event['type']}" + ( " is TOMORROW\n" if delta.seconds / 3600 > 0 else "TODAY\n") else: message += f"{u_event['name']} {u_event['type']} in {delta.days}" + ( f"days\n" if delta.days > 1 else "day\n") bot.send_message(chat_id=update.message.chat_id, text=message)
def delete_event(bot, update): typing(bot, update) if status['delete_event'] == 0: message = "OH NO you are deleting an event 😧" bot.send_message(chat_id=update.message.chat_id, text=message) message = "Enter your friend Name:" bot.send_message(chat_id=update.message.chat_id, text=message) status['delete_event'] = 3 elif status['delete_event'] == 3: status['delete_event'] -= 1 e = Event(settings.HOST, settings.DB) ev = e.get_events_by_name(update.message.text) if len(ev) == 0: status['delete_event'] = 0 message = "🤔 you friend does not have this event" bot.send_message(chat_id=update.message.chat_id, text=message) return delete.append(update.message.text) message = "" for event in ev: message += "=> {} on {}\n".format(event["type"], event["date"]) message += "enter type event:" bot.send_message(chat_id=update.message.chat_id, text=message) elif status['delete_event'] == 2: status['delete_event'] -= 1 type = update.message.text delete.append(type) message = "enter date of event:" bot.send_message(chat_id=update.message.chat_id, text=message) elif status['delete_event'] == 1: status['delete_event'] -= 1 date = update.message.text date = date.split('/') date = [int(d) for d in date] date = datetime.datetime(*date) delete.append(date) e = Event(settings.HOST, settings.DB) e.delete_event(*delete) message = "Deleted :(" bot.send_message(chat_id=update.message.chat_id, text=message)
def setUp(self): super(TestDynamoDBCreateTableAndFillCase, self).setUp() # Create the tables if Client.exists(): Client.delete_table() Client.create_table(wait=True) if Staff.exists(): Staff.delete_table() Staff.create_table(wait=True) if Event.exists(): Event.delete_table() Event.create_table(wait=True) if EventPeople.exists(): EventPeople.delete_table() EventPeople.create_table(wait=True) # fill client table with Client.batch_write() as p_batch: persons = self.create_person_item(50) for person in persons: print('Client name - ', person.name) p_batch.save(person) # fill staff table with Staff.batch_write() as p_batch: persons = self.create_person_item(50) for person in persons: print('Staff name - ', person.name) p_batch.save(person) # fill event table with Event.batch_write() as event_batch: events = self.create_list_events(10) for event in events: print('id={0}, event start time={1}, event service name='.format(event.event_id, event.start_time, event.service.name)) event_batch.save(event)
def test_table_counts(self): self.assertEqual(Client.count() + Staff.count(), 100) self.assertEqual(Event.count(), 10)
def test_search_on_event_date(self): count = 0 for event in Event.scan(Event.start_time.between(parser.parse("Mar 1 00:00:00 PST 2018"), parser.parse("Mar 10 23:59:00 PST 2018"))): count += 1 self.assertEqual((Event.count()/2), count)
def test_search_all_events_for_person(self): for event in Event.scan(limit=5): event.add_people([Client.get('*****@*****.**'), Staff.get('*****@*****.**')]) events = Client.get('*****@*****.**').get_events_for_person() self.assertEqual(len(events), 5)