def should_add_schedules_directly(self): timezone_1 = Timezone('Abu Dhabi') timezone_2 = Timezone('Pacific (US & Canada)') l1_1 = WeeklyLesson(start_time=0, day_of_week=0) l1_2 = WeeklyLesson(start_time=1, day_of_week=0) l1_3 = WeeklyLesson(start_time=0.5, day_of_week=0) l2_1 = WeeklyLesson(start_time=0, day_of_week=0) l2_2 = WeeklyLesson(start_time=1, day_of_week=0) l2_3 = WeeklyLesson(start_time=0.5, day_of_week=0) lessons_1 = [l1_1, l1_2, l1_3] lessons_2 = [l2_1, l2_2, l2_3] s_1 = Schedule(lessons=lessons_1, timezone=timezone_1) s_2 = Schedule(lessons=lessons_2, timezone=timezone_2) s_3 = s_1.add_schedule(s_2, timezone=None) expect(s_3.freq_lessons_at(start_time=0, day_of_week=0)).to.equal(2) expect(s_3.freq_lessons_at(start_time=1, day_of_week=0)).to.equal(2) expect(s_3.freq_lessons_at(start_time=0.5, day_of_week=0)).to.equal(2) expect(s_3.freq_lessons_at(start_time=23.5, day_of_week=5)).to.equal(0)
def __init__(self, day_of_week_range=(0, 7,), start_time_range=(0, 23.75,), timezone=None): dw_low, dw_high = day_of_week_range self._day_of_week = np.random.randint(low=dw_low, high=dw_high) # [0,6]; seven days in a week self._start_time = self.generate_start_time(start_time_range) # [0, 23.75] self._timezone = timezone or np.random.choice(Timezone.mapping().values())
def should_delegate_to_df(self): l1_1 = WeeklyLesson(start_time=0, day_of_week=0) l1_2 = WeeklyLesson(start_time=1, day_of_week=0) l1_3 = WeeklyLesson(start_time=0.5, day_of_week=0) lessons_1 = [l1_1, l1_2, l1_3] s = Schedule(lessons=lessons_1, timezone=Timezone('Abu Dhabi')) expect(s.sum().sum()).to.equal(3)
def should_return_the_timezone_object(self): timezone = Timezone('Abu Dhabi') l1_1 = WeeklyLesson(start_time=0, day_of_week=0) l1_2 = WeeklyLesson(start_time=1, day_of_week=0) l1_3 = WeeklyLesson(start_time=0.5, day_of_week=0) lessons = [l1_1, l1_2, l1_3] s = Schedule(lessons=lessons, timezone=timezone) expect(s.timezone()).to.equal(timezone)
async def save(client, message, option): if option == 'repeat': #TODO make it add not overwrite reminder_time = Timezone().convertToSystemTime(message) text = message.content.split(' ', 4)[4] how_many = message.content.split(' ', 4)[3] with open('reminderRepeat.json') as infile: reminder_repeat = json.load(infile) reminder_repeat[message.author.name] = { "time": reminder_time, "message": text, "how_many": how_many } with open('reminderRepeat.json', 'w') as outfile: json.dump(reminder_repeat, outfile) await client.send_message(message.channel, 'Reminder set.') else: #TODO make it add not overwrite reminder_time = Timezone().convertToSystemTime(message) text = message.content.split(' ', 3)[3] with open("reminder.json") as infile: reminder = json.load(infile) reminder[message.author.name] = { "time": reminder_time, "message": text, "date": option } with open("reminder.json", 'w') as outfile: json.dump(reminder, outfile) await client.send_message(message.channel, 'Reminder set.')
def __init__(self, data_df): self._data_df = data_df self._schedule = Schedule() for i in data_df.index.values: row = data_df.ix[i] lessons = [] for j in range(1, int(row.schedule_type + 1)): lessons.append( WeeklyLesson(start_time=row['l{}_time'.format(j)], day_of_week=row['l{}_day'.format(j)])) new_value = self._schedule.add_schedule( Schedule(lessons=lessons, timezone=Timezone(row['user_tz']))) self._schedule = new_value
def should_convert_to_standard(self): tz = Timezone('Abu Dhabi') expect(tz.to_standard()).to.equal('Asia/Muscat')
async def check(self, client): if os.path.isfile("timezone.txt"): pass else: Timezone.tzList(self) if os.path.isfile("users.json"): pass else: with open("users.json", "w") as fr: fr.write("{}") if os.path.isfile("reminder.json"): pass else: with open("reminder.json", "w") as frr: frr.write("{}") if os.path.isfile("reminderRepeat.json"): pass else: with open("reminderRepeat.json", "w") as frrr: frrr.write("{}") self.purge() dateFMT = "%m/%d/%Y" timeFMT = "%H:%M" current_date = datetime.today().date() within_hour = (datetime.today() + timedelta(hours=1)).strftime(timeFMT) with open("reminder.json", "r+") as data_file_reminder: data_reminder = json.load(data_file_reminder) for data_reminder_each in data_reminder: message_date = datetime.strptime(data_reminder[data_reminder_each]["date"], dateFMT).date() message_time = data_reminder[data_reminder_each]["time"] if message_time <= within_hour and message_date == current_date: message = data_reminder[data_reminder_each]["message"] serv = discord.utils.find(lambda m: m.name == Chatbot("settings.txt").server_name, client.servers) user = discord.utils.find(lambda m: m.name == data_reminder_each, serv.members) time_seconds = datetime.strptime(message_time, timeFMT) - datetime.strptime( datetime.today().strftime(timeFMT), timeFMT ) await asyncio.sleep(time_seconds.seconds) await client.send_message(user, message) with open("reminderRepeat.json", "r+") as data_file_reminder_repeat: data_reminder_repeat = json.load(data_file_reminder_repeat) for data_reminder_repeat_each in data_reminder_repeat: message_time = data_reminder_repeat[data_reminder_repeat_each]["time"] if message_time <= within_hour: message = data_reminder_repeat[data_reminder_repeat_each]["message"] serv = discord.utils.find(lambda m: m.name == Chatbot("settings.txt").server_name, client.servers) user = discord.utils.find(lambda m: m.name == data_reminder_repeat_each, serv.members) time_seconds = datetime.strptime(message_time, timeFMT) - datetime.strptime( datetime.today().strftime(timeFMT), timeFMT ) await asyncio.sleep(time_seconds.seconds) await client.send_message(user, message) data_reminder_repeat[data_reminder_repeat_each]["how_many"] = ( int(data_reminder_repeat[data_reminder_repeat_each]["how_many"]) - 1 ) data_file_reminder_repeat.seek(0) data_file_reminder_repeat.write(json.dumps(data_reminder_repeat)) data_file_reminder_repeat.truncate()
def should_be_in_standard_tz_format(tz_string): mapping = Timezone.mapping() standard_timezones = mapping.values() return tz_string in standard_timezones
async def check(self, client): if os.path.isfile("timezone.txt"): pass else: Timezone.tzList(self) if os.path.isfile("users.json"): pass else: with open("users.json", 'w') as fr: fr.write("{}") if os.path.isfile('reminder.json'): pass else: with open('reminder.json', "w") as frr: frr.write("{}") if os.path.isfile('reminderRepeat.json'): pass else: with open('reminderRepeat.json', "w") as frrr: frrr.write("{}") self.purge() dateFMT = '%m/%d/%Y' timeFMT = '%H:%M' current_date = datetime.today().date() within_hour = (datetime.today() + timedelta(hours=1)).strftime(timeFMT) with open('reminder.json', 'r+') as data_file_reminder: data_reminder = json.load(data_file_reminder) for data_reminder_each in data_reminder: message_date = datetime.strptime( data_reminder[data_reminder_each]['date'], dateFMT).date() message_time = data_reminder[data_reminder_each]['time'] if message_time <= within_hour and message_date == current_date: message = data_reminder[data_reminder_each]['message'] serv = discord.utils.find( lambda m: m.name == Chatbot('settings.txt'). server_name, client.servers) user = discord.utils.find( lambda m: m.name == data_reminder_each, serv.members) time_seconds = datetime.strptime( message_time, timeFMT) - datetime.strptime( datetime.today().strftime(timeFMT), timeFMT) await asyncio.sleep(time_seconds.seconds) await client.send_message(user, message) with open('reminderRepeat.json', 'r+') as data_file_reminder_repeat: data_reminder_repeat = json.load(data_file_reminder_repeat) for data_reminder_repeat_each in data_reminder_repeat: message_time = data_reminder_repeat[data_reminder_repeat_each][ 'time'] if message_time <= within_hour: message = data_reminder_repeat[data_reminder_repeat_each][ 'message'] serv = discord.utils.find( lambda m: m.name == Chatbot('settings.txt'). server_name, client.servers) user = discord.utils.find( lambda m: m.name == data_reminder_repeat_each, serv.members) time_seconds = datetime.strptime( message_time, timeFMT) - datetime.strptime( datetime.today().strftime(timeFMT), timeFMT) await asyncio.sleep(time_seconds.seconds) await client.send_message(user, message) data_reminder_repeat[data_reminder_repeat_each][ 'how_many'] = int( data_reminder_repeat[data_reminder_repeat_each] ['how_many']) - 1 data_file_reminder_repeat.seek(0) data_file_reminder_repeat.write( json.dumps(data_reminder_repeat)) data_file_reminder_repeat.truncate()
import discord from cleverbot import cleverbot from chatbot import Chatbot from polls import Poll from reminder import Reminder from timezone import Timezone from trivia import Trivia # Set up the logging module to output diagnostic to the console. logging.basicConfig() # Create new instances of bot objects bot = Chatbot('settings.txt') remind_module = Reminder() timezone_module = Timezone() trivia_module = Trivia() poll_module = Poll() #cleverbot object clever_bot = cleverbot.Session() # Initialize client object, begin connection client = discord.Client() serv = '' # Event handler @client.event async def on_member_join(newmember):