async def echo_message(msg: types.Message): print(msg.from_user.id) print(msg.text) Text = msg.text Kb = None flag = True if msg.text == '↩': Text = open('help.txt', 'r', encoding='utf-8').read() Kb = btns.MENUkb elif msg.text in btns.dictKB: boxKB = btns.dictKB[msg.text] if boxKB[-2] == 'S': Kb = boxKB[0] if boxKB[1]: Text = eval(boxKB[1]) elif boxKB[-2] == 'H': #проверка на наличие данных if msg.text == 'Все события': for i in database.get_events('all'): print(90) Eventdict = i flag = False text = '' text += Eventdict['@TITLE'] text += '\n' + Eventdict['@DATEOFBUBLICATION'] text += '\n' + Eventdict['@DATEOFSTART'] text += '\n' + Eventdict['@DATEOFFINISH'] text += '\n' + Eventdict['@STATUSOFSPECIALITY'] text += '\n' + Eventdict['@STATUSOFSCHOOL'] text += '\n' + Eventdict['@STATUSOFCLASS'] text += '\n' + Eventdict['@DESCRIPTION'] await bot.send_message(msg.from_user.id, text) elif msg.text == 'Расписание 🗓': if database.chek_user(msg['chat']['id'], 'class') and boxKB[-1]: ph = open('data/data/' + database.get_class_user(msg.from_user.id) + '.jpg', 'rb') await bot.send_photo(msg.from_user.id, ph) else: Kb = boxKB[0] Text = 'Укажите свой класс' elif msg.text == 'Расписание занятий🗓': """ for i in database.get_schedule_itcube(): text = '' for j in i: text += str(j) + '\n' await bot.send_message(msg.from_user.id, text) """ Kb = boxKB[0] Text = 'Укажите свою секцию' else: Kb = boxKB[0] Text = 'Укажите свой класс' elif boxKB[-2] == 'D': boxKB = btns.dictKB[msg.text] Kb = eval(boxKB[1].replace('Utl_id', 'msg.from_user.id').replace('msgtext', 'msg.text')) if flag: await bot.send_message(msg.from_user.id, Text, reply_markup=Kb)
def print_week(year, week): #Store all of the Days & Holidays WeekList = [] HolidayDates = [] HolidayNames = [] AssignedDates = [] AssignedNames = [] #Print the dates of the week (M-F only) for d in daysOfWeek(year, week): WeekList.append(d) from database import get_events school_events = get_events("1") for x in range(0, len(school_events)): #There is a day off this week if str(school_events[x][1]) == str(d): HolidayDates.append(d) HolidayNames.append(school_events[x][2]) from database import get_all_assigned assigned_dates = get_all_assigned() for i in range(0, len(assigned_dates)): if (str(assigned_dates[i][2]) == str(d)): AssignedDates.append(d) AssignedNames.append(assigned_dates[i][1]) #Replace Holiday into original class list for x in range(0, len(HolidayDates)): #Find spot for i in range(0, len(WeekList)): #Replace if (str(WeekList[i]) == str(HolidayDates[x])): WeekList[i] = str(HolidayDates[x]) + " School Closed - " + str(HolidayNames[x]) + " covered by - ***NOBODY*** " #Check assigned for j in range (0, len(AssignedDates)): if (str(HolidayDates[x])) == (str(AssignedDates[j])): WeekList[i] = WeekList[i].strip(" covered by - ***NOBODY***") WeekList[i] = WeekList[i] + " covered by - " WeekList[i] = WeekList[i] + AssignedNames[j] #Print the entire week out (M-F only) for x in range(0, len(WeekList)): print WeekList[x]
def get_actual_event(cursor): actual_time = None if settings.loaded['use_time_mock']: get_mock_time() actual_time = settings.runtime['actual_time'] else: actual_time = datetime.datetime.now() # print("Actual Time == ", actual_time) stored_events = database.get_events(cursor) for stored_event in stored_events: if get_date_from_event( stored_event[2], settings.loaded['event_dates_in_utc'] ) <= actual_time: # if the start_event time was before if get_date_from_event( stored_event[0], settings.loaded['event_dates_in_utc'] ) >= actual_time: # if the end_event still not done # print("IN EVENT: ", stored_event[1]) # Show event summary return stored_event # returns the found event
def handle_request(sock): global peers global fed_peers # Read JSON request jstr = read_string(sock) if jstr is None: return try: data = json.loads(jstr) except: # Client send invalid json write_msg(sock, RESPONSE_INVALID_REQUEST, {}, False) return # Check that request is formatted correctly if not "version_major" in data or not "version_minor" in data or not "type" in data: sock.close() return # Check client version major_version = data["version_major"] minor_version = data["version_minor"] if major_version != API_VERSION_MAJOR: # Throw version mismatch error write_msg(sock, RESPONSE_VERSION_MISMATCH, {}, False) return # Add to our peers list if they aren't in it already ip = sock.getpeername()[0] add_peer(ip) # Switch by request type if data["type"] == REQUEST_HANDSHAKE: if not "peers" in data: write_msg(sock, RESPONSE_UNKNOWN, {}, False) return handle_handshake(data) write_msg(sock, RESPONSE_OK, {"peers": peers}, False) elif data["type"] == REQUEST_PUSH: # Perform push if not "events" in data or not "competition" in data: write_msg(sock, RESPONSE_UNKNOWN, {}, False) return ret = database.push_events(data["competition"], data["events"]) # Return push status response = RESPONSE_OK if ret == 1: response = RESPONSE_UNKNOWN elif ret == 2: response = RESPONSE_SIGNATURE_REJECTED write_msg(sock, response, {}, False) elif data["type"] == REQUEST_PULL: # Fetch events from database if not "competition" in data: write_msg(sock, RESPONSE_UNKNOWN, {}, False) sock.close() return events = database.get_events(data["competition"]) write_msg(sock, RESPONSE_OK, {"events": events}, False) elif data["type"] == REQUEST_DUMP_MATCHES: if not "competition" in data: write_msg(sock, RESPONSE_UNKNOWN, {}) sock.close() return matches = database.dump_matches(data["competition"]) write_msg(sock, RESPONSE_OK, {"matches": matches}, False) elif data["type"] == REQUEST_SEASON: if not "year" in data: write_msg(sock, RESPONSE_UNKNOWN, {}, False) return comps = database.list_competitions(data["year"]) write_msg(sock, RESPONSE_OK, { "competitions": comps, "teams": database.get_teams() }, False) else: write_msg(sock, RESPONSE_INVALID_REQUEST, {}, False)
def push(addr, competition): write_msg_new(addr, REQUEST_PUSH, { "events": database.get_events(competition), "competition": competition })
def events_list_index(): return render_template("events.html", events=database.get_events())
def events(): return dumps(database.get_events())
def print_school(): from database import get_events school_events = get_events("1") for x in range(0, len(school_events)): print str(school_events[x][1]) + " " + school_events[x][2]