def view_vote_answer(message, chat, shared): if message.text == 'Back\U0001F519': chat.send('Choose a command:') return if message.text not in ['Date', 'Subject', 'Average']: keyboard = pzgram.create_keyboard([['Date', 'Subject'], ['Average']]) chat.send('You give me a bad answer, please select an option:', reply_markup=keyboard) return if message.text == 'Date': convert_type = {'Practice': 'P', 'Oral': 'O', 'Written': 'W'} votes = SQL_function.get_vote_date() m = "Here's your votes:\n" for i in votes: subj = i[2] subj = shared['subjects'][subj] m += f'{i[0]} - {subj} {convert_type[i[3]]} - {i[1][0:2]}/{i[1][2:4]}\n' chat.send(m) shared['status'] = '' shared['cache'] = {} elif message.text == 'Subject': chat.send('Select a subject', reply_markup=shared['keyboards']['subj']) shared['status'] = 'viewVotesSubj' else: keyboard = pzgram.create_keyboard([['With Type', 'All votes']]) chat.send('Select a type:', reply_markup=keyboard) shared['status'] = 'viewVotesAvg'
def new_vote_type(message, chat, shared): if message.text == 'Back\U0001F519': chat.send('Ok, now send me the subject', reply_markup=shared['keyboards']['subj']) shared['status'] = 'newVote3' return if message.text not in ['Written', 'Oral', 'Practice']: keyboard = pzgram.create_keyboard([['Written', 'Oral'], ['Practice']], one=True) chat.send('Select the kind of this vote:', reply_markup=keyboard) return cache = shared['cache'] cache['type'] = message.text keyboard = pzgram.create_keyboard([['Yes', 'No']], one=True) chat.send('Do you want to add some notes to this vote?', reply_markup=keyboard) shared['cache'] = cache shared['status'] = 'newVote5'
def view_manage_date(message, chat, shared): if message.text == 'Back\U0001F519': chat.send('Select a command:') return start_date, stop_date = '', '' month_length = [00, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] if message.text == 'This Week': start_date = datetime.now().strftime('%m%d') stop_date = (datetime.now() + timedelta(days=(7-int(datetime.now().strftime('%u'))))).strftime('%m%d') elif message.text == 'Next Week': start_date = (datetime.now() + timedelta(days=(8-int(datetime.now().strftime('%u'))))).strftime('%m%d') stop_date = (datetime.strptime(start_date, '%m%d') + timedelta(days=6)).strftime('%m%d') elif message.text == 'This Month': start_date = datetime.now().strftime('%m%d') this_m = datetime.now().strftime('%m') stop_date = this_m+str(month_length[int(this_m)]) elif message.text == 'Next Month': this_m = datetime.now().month next_m = (datetime.now() + timedelta(days=month_length[int(this_m)])).strftime('%m') start_date = next_m + '01' stop_date = next_m + str(month_length[int(next_m)]) if start_date != '' and stop_date != '': m, k, conv_dict = useful_function.view_tasks_between(start_date, stop_date) if m == '': m = 'You have no tasks in this period, select another one' keyboard = pzgram.create_keyboard( [['This Week', 'Next Week'], ['This Month', 'Next Month'], ['Other', 'Back\U0001F519']], one=True) chat.send(m, reply_markup=keyboard) else: chat.send(m, reply_markup=k) shared['cache'] = {'conv_dict': conv_dict, 'comm_keyb': k, 'message': m} shared['status'] = 'view2'
def view_one(message, chat, shared): if message.text == 'Back\U0001F519': view_calendar(chat, shared) return cache = shared['cache'] if message.text not in cache['conv_dict']: chat.send('Error, please select another one', reply_markup=cache['comm_keyb']) return row = cache['conv_dict'][message.text] if row[0] == 't': test = SQL_function.get_one_row('Test', row[1:]) m = '*' + test[0] + ' Test*\n' year = '2018' if int(test[1][0:2]) >= 7: year = '2017' date = datetime.strptime(test[1]+year, '%m%d%Y').strftime('%a %d %b') # Ex. Mon 12 Feb m += date + '\n' m += test[2] + '\n' keyboard = [['Menu\U0001F3B2', 'Edit Date'], ['Edit Subj', 'Edit Arg', 'Edit Notes'], ['Back\U0001F519']] if test[3] is not None: m += test[3] keyboard = pzgram.create_keyboard(keyboard, one=True) chat.send(m, reply_markup=keyboard) cache['one_message'] = m shared['status'] = 'view3' cache['keyb'] = keyboard cache['row'] = row elif row[0] == 'h': hw = SQL_function.get_one_row('Homework', row[1:]) m = '*' + hw[0] + ' Homework*\n' year = '2018' if int(hw[1][0:2]) >= 7: year = '2017' date = datetime.strptime(hw[1] + year, '%m%d%Y').strftime('%a %d %b') # Ex. Mon 12 Feb m += date + '\n' m += hw[2] + '\n' keyboard = [['Menu\U0001F3B2', 'Completed\U00002611'], ['Edit Date', 'Edit Subj', 'Edit Notes'], ['Back\U0001F519']] if hw[3]: m += '_Completed\U00002611_' keyboard = [['Menu\U0001F3B2', 'Back\U0001F519'], ['Edit Date', 'Edit Subj', 'Edit Notes']] keyboard = pzgram.create_keyboard(keyboard, one=True) chat.send(m, reply_markup=keyboard) cache['one_message'] = m shared['status'] = 'view3' cache['keyb'] = keyboard cache['row'] = row shared['cache'] = cache
def new_vote_notes_ask(message, chat, shared): if message.text not in ['Yes', 'No']: chat.send('You only answer me with *yes* or *no*') keyboard = pzgram.create_keyboard([['Yes', 'No']], one=True) chat.send('Do you want to add some notes to this vote?', reply_markup=keyboard) return if message.text == 'Yes': chat.send('Ok, send me the notes to attach at this vote', no_keyboard=True) shared['status'] = 'newVote6' else: cache = shared['cache'] SQL_function.add_new_vote(cache['number'], cache['subject'], cache['type'], cache['date']) chat.send('Vote added') shared['status'] = ''
def view_times_send(message, chat, shared): if message.text not in ['Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat']: day_keyboard = pzgram.create_keyboard([['Mon', 'Tue', 'Wed'], ['Thr', 'Fri', 'Sat']], one=True) chat.send("Please, select one of this day:", reply_markup=day_keyboard) return convert_dict = {'Mon': 0, 'Tue': 1, 'Wed': 2, 'Thr': 3, 'Fri': 4, 'Sat': 5} number_day = convert_dict[message.text] times = shared['times'] subjects = times['days'][number_day]['subjects'] m = '' for n, s in enumerate(subjects, start=1): m += str(n) + ' ' + s + '\n' chat.send(m) shared['status'] = ''
def find_ask_date(message, chat, shared): # TODO: bold the day with tasks if message.text == 'Back\U0001F519': chat.send('Choose a command:') return options = ['Homeworks', 'Tests', 'Both'] if message.text not in options: keyboard = pzgram.create_keyboard([['Homeworks', 'Tests'], ['Both']], one=True) chat.send("Select a type from the keyboard:", reply_markup=keyboard) return cache = shared['cache'] cache['option'] = message.text chat.send('Now select a date:', reply_markup=shared['keyboards']['this_m_test']) cache['conv_dict'] = shared['keyboards']['this_m_c'] shared['status'] = 'find2' shared['cache'] = cache
def view_tasks_between(start, stop): tests, homeworks = SQL_function.find_between(start, stop) s = '' current_date = start keyboard = [] conv_dict = {} row = -1 while True: smt_found = False # something year = '18' if int(start[0:2]) >= 7: year = '17' current_day = datetime.strptime(current_date + year, '%m%d%y').strftime('%a') formatted_date = current_date[2:4] + '/' + current_date[0:2] for t in tests: if t[2] == current_date: if not smt_found: smt_found = True s += '*' + current_day + ' ' + formatted_date + '*\n' keyboard.append([]) row += 1 r = t[1] + ' test' s += r + '\n' keyboard[row].append(formatted_date + ' ' + r) conv_dict[formatted_date + ' ' + r] = 't' + str(t[0]) for h in homeworks: if h[2] == current_date: if not smt_found: smt_found = True s += '*' + current_day + ' ' + formatted_date + '*\n' keyboard.append([]) row += 1 r = h[1] + ' homework' s += r + '\n' keyboard[row].append(formatted_date + ' ' + r) conv_dict[formatted_date + ' ' + r] = 'h' + str(h[0]) if current_date == stop: break current_date = (datetime.strptime(current_date, '%m%d') + timedelta(days=1)).strftime('%m%d') keyboard.append(['Menu\U0001F3B2', 'Back\U0001F519']) keyboard = pzgram.create_keyboard(keyboard, one=True) return s, keyboard, conv_dict
def view_vote_average(message, chat, shared): if message.text not in ['With Type', 'All votes']: keyboard = pzgram.create_keyboard([['With Type', 'All votes']]) chat.send('Please, select a valid type:', reply_markup=keyboard) return if message.text == 'With Type': avg = SQL_function.get_average(True) convert_type = {'Practice': 'Pr', 'Oral': 'Or', 'Written': 'Wr'} m = "Here's your averages:" for i in avg: m += i[0] + ' - ' + shared['subject'][i[1]] + ' ' + convert_type[i[2]] + '\n' chat.send(m) else: avg = SQL_function.get_average(False) m = "Here's your averages:" for i in avg: m += i[0] + ' - ' + shared['subject'][i[1]] + ' ' + '\n' chat.send(m) shared['status'] = '' shared['cache'] = ''
def new_vote_subj(message, chat, shared): if message.text == 'Back\U0001F519': chat.send('Now send me the date of this test', reply_markup=shared['keyboards']['this_m_test']) shared['cache']['conv_dict'] = shared['keyboards']['this_m_c'] shared['status'] = 'newVote2' return subj = shared['subjects'] cache = shared['cache'] for i in subj: if subj[i] == message.text: cache['subject'] = i break else: chat.send('The subject that you chose is not correct, retry') chat.send("Select the subject:", reply_markup=shared['keyboards']['subj']) return keyboard = pzgram.create_keyboard([['Written', 'Oral'], ['Practice']], one=True) chat.send('Select the kind of this vote:', reply_markup=keyboard) shared['cache'] = cache shared['status'] = 'newVote4'
def set_keyboard(shared): month = int(datetime.now().strftime('%m')) days_l, days_c = useful_function.create_hw_keyboard() # 'Default Keyboard' this_m_l, this_m_c = useful_function.create_this_month_keyboard() # All days of this m next_m_l, next_m_c = useful_function.create_month_keyboard(month+1) # All days of next m days = pzgram.create_keyboard(days_l, one=True) this_m = pzgram.create_keyboard(this_m_l, one=True) this_m_test_l = this_m_l.copy() this_m_test_l.insert(-1, ['Next Month', 'Other']) this_m_vote_l = this_m_l.copy() this_m_vote_l.insert(-1, ['Prev Month', 'Other']) this_m_vote = pzgram.create_keyboard(this_m_vote_l, one=True) # Like this month, with prev button this_m_test = pzgram.create_keyboard(this_m_test_l, one=True) # Like this month, with buttons next_m = pzgram.create_keyboard(next_m_l, one=True) all_month = pzgram.create_keyboard(useful_function.create_all_month_keyboard(), one=True) subj = [[], [], []] for i, s in enumerate(shared['subjects']): subj[i // 3].append(shared['subjects'][s]) subj.append(['Menu\U0001F3B2', 'Back\U0001F519']) subj = pzgram.create_keyboard(subj, one=False) shared['keyboards'] = {'days': days, 'this_m': this_m, 'next_m': next_m, 'all_month': all_month, 'this_m_test': this_m_test, 'days_c': days_c, 'this_m_c': this_m_c, 'next_m_c': next_m_c, 'subj': subj, 'this_m_vote': this_m_vote}
def start_command(chat): keyboard = pzgram.create_keyboard([["/Ora", "/1min", "/10min", "/1h"]]) chat.send("Select a command", reply_markup=keyboard)
def start_command(chat): keyboard = pzgram.create_keyboard([["/Temperatura", "/Luce"], ["/Altitudine", "/Pressione"]]) chat.send("Select a command", reply_markup=keyboard)
def show_press(chat): keyboard = pzgram.create_keyboard([["/InstantPrs", "/LastMinPrs"], ["/Last10MinPrs", "/LastHourPrs"]]) chat.send("Select a command", reply_markup=keyboard)
def show_temp(chat): keyboard = pzgram.create_keyboard([["/InstantTmp", "/LastMinTmp"], ["/Last10MinTmp", "/LastHourTmp"]]) chat.send("Select a command", reply_markup=keyboard)
def show_lux(chat): keyboard = pzgram.create_keyboard([["/InstantLux", "/LastMinLux"], ["/Last10MinLux", "/LastHourLux"]]) chat.send("Select a command", reply_markup=keyboard)
def show_alt(chat): keyboard = pzgram.create_keyboard([["/InstantAlt", "/LastMinAlt"], ["/Last10MinAlt", "/LastHourAlt"]]) chat.send("Select a command", reply_markup=keyboard)
def manage_date(message, chat, shared): # possible input status: newHW, newTest, editDate, find2, newVote2 k_hist = shared['k_hist'] c_hist = shared['c_hist'] cache = shared['cache'] conv_dict = cache['conv_dict'] month_dict = {'Jan': '01', 'Feb': '02', 'Mar': '03', 'Apr': '04', 'May': '05', 'Jun': '06', 'Jul': '07', 'Aug': '08', 'Sep': '09', 'Oct': '10', 'Nov': '11', 'Dec': '12'} if message.text in conv_dict: cache['date'] = conv_dict[message.text] if shared['status'] == 'editDate': set_new_date(chat, cache, shared) return if shared['status'] == 'find2': find_gave_result(chat, cache, shared) return if shared['status'] == 'newVote2': new_vote_date(chat, cache, shared) return chat.send('Ok, now select a subject:', reply_markup=shared['keyboards']['subj']) if shared['status'] == 'newHW': shared['status'] = 'newHW2' elif shared['status'] == 'newTest': shared['status'] = 'newTest2' elif message.text == 'This Month': chat.send('Select a day', reply_markup=shared['keyboards']['this_m']) cache['conv_dict'] = shared['keyboards']['this_m_c'] shared['cache'] = cache k_hist.append('this_m') c_hist.append('this_m_c') elif message.text == 'Next Month': chat.send('Select a day', reply_markup=shared['keyboards']['next_m']) cache['conv_dict'] = shared['keyboards']['next_m_c'] shared['cache'] = cache k_hist.append('next_m') c_hist.append('newxt_m_c') elif message.text == 'Other': chat.send('Select a month', reply_markup=shared['keyboards']['all_month']) k_hist.append('all_month') c_hist.append('') elif message.text in month_dict: month = month_dict[message.text] key_list, conv_dict = useful_function.create_month_keyboard(month) keyboard = pzgram.create_keyboard(key_list, one=True) chat.send('Now select a day:', reply_markup=keyboard) cache['conv_dict'] = conv_dict k_hist.append('') c_hist.append('') elif message.text == 'Prev Month': this_m = int(datetime.now().month) if this_m == 1: prev = 12 else: prev = this_m-1 key_list, conv_dict = useful_function.create_month_keyboard(prev) keyboard = pzgram.create_keyboard(key_list, one=True) chat.send('Select a day:', reply_markup=keyboard) cache['conv_dict'] = conv_dict k_hist.append('') c_hist.append('') elif message.text == 'Back\U0001F519': if len(k_hist): k_hist.pop() exec("chat.send('Select a day:', reply_markup=shared['keyboards]['"+k_hist[-1]+"'])") c_hist.pop() if c_hist[-1] != '': exec("cache['conv_dict] = shared['keyboards]['"+c_hist[-1]+"']") else: if shared['status'] == 'newHW' or shared['status'] == 'newTest': chat.send('Choose a command:') shared['status'] = '' elif shared['status'] == 'find2': find_command(chat, shared) elif shared['status'] == 'newVote2': new_vote_command(chat, shared) elif shared['status'] == 'editDate': chat.send(shared['cache']['one_message'], reply_markup=shared['cache']['keyb']) shared['status'] = 'view3' else: status = shared['status'] if status == 'newHW': chat.send('The day that you give me is not correct') new_homework(chat, shared) elif status == 'newTest': chat.send('The day that you give me is not correct') new_test(chat, shared) elif status == 'editDate' or status == 'find2': chat.send('The day that you give me is not correct, retry', reply_markup=shared['keyboards']['this_m_test']) cache['conv_dict'] = shared['keyboards']['this_m_c'] elif status == 'newVote2': chat.send('The day that you give me is not correct, retry', reply_markup=shared['keyboards']['this_m_vote']) cache['conv_dict'] = shared['keyboards']['this_m_c'] shared['k_hist'] = k_hist shared['c_hist'] = c_hist shared['cache'] = cache
def view_times_command(chat, shared): day_keyboard = pzgram.create_keyboard([['Mon', 'Tue', 'Wed'], ['Thr', 'Fri', 'Sat']], one=True) chat.send("Select a day:", reply_markup=day_keyboard) shared['status'] = 'times'
def view_calendar(chat, shared): keyboard = pzgram.create_keyboard([['This Week', 'Next Week'], ['This Month', 'Next Month'], ['Other', 'Back\U0001F519']], one=True) chat.send('Select a period', reply_markup=keyboard) shared['status'] = 'view'
def view_vote_command(chat, shared): keyboard = pzgram.create_keyboard([['Date', 'Subject'], ['Average'], ['Menu\U0001F3B2', 'Back\U0001F519']]) chat.send('Select an option:', reply_markup=keyboard) shared['status'] = 'viewVotes'
def find_command(chat, shared): keyboard = pzgram.create_keyboard([['Homeworks', 'Tests'], ['Both'], ['Menu\U0001F3B2', 'Back\U0001F519']], one=True) chat.send('Select wich type of tasks you want to find:', reply_markup=keyboard) shared['cache'] = {} shared['status'] = 'find1'