class MarkInfoPopup(Popup): json = MarksJson() store = json.get_json() description = ObjectProperty() mark = ObjectProperty() date = ObjectProperty() trim = ObjectProperty() value = ObjectProperty() grouped = ObjectProperty() def __init__(self, current_subject, key, trim): super(MarkInfoPopup, self).__init__() self.subject = current_subject self.key = str(key.split('-')[0].strip()) self.description.text = 'Description: {}'.format(self.key) self.mark.text = 'Mark: {}'.format( self.store[self.subject]['marks'][trim][self.key]['mark'][0]) self.date.text = 'Date: {}'.format( self.store[self.subject]['marks'][trim][self.key]['date']) self.trim.text = 'Trimester: {}'.format(str(trim)) self.value.text = 'Value: {}'.format( self.store[self.subject]['marks'][trim][self.key]['value']) self.grouped.text = 'Grouped: {}'.format( self.store[self.subject]['marks'][trim][self.key]['grouped'])
def get_text(self, user_id, what): ''' Get user launguage code from DB and text from JSON by lng code ''' lang = self._sql_execute( f'SELECT `lang` FROM `users` WHERE `id` = "{user_id}"' ) return get_json( open(f'lang/{lang}.json', 'r', encoding='utf-8').read() )[what]
def __init__(self, filename): """Tries to open the json file and read the data from it""" try: datafile = codecs.open(filename, "r", "utf-8") self.data = get_json(datafile) datafile.close() #__import__("pprint").pprint(self.data) except Exception as e: self.data = {} print(e)
def getInfo(): if (request.method == 'GET'): print("\n") response = list() print("RECIEVED INFO REQUEST FROM " + str(request.remote_addr)) for i in range(len(users)): response.append({ 'name': users[i].getName(), 'ip': users[i].getIP(), 'ready': users[i].isReady() }) json = jsonify({'players': response}) print("RESPONSE to " + str(request.remote_addr) + " " + str(json.get_json())) return json
def read_compiled_file(self): """Attempts to read the compiled file for data""" p = path.join(self.paths["internal"], "_compiled.sctpy") print("Loading compiled data from \"{}\"...".format(p), end="") if path.exists(p): try: cpfile = open(p, "r") self.compiled = get_json(cpfile) cpfile.close() print("Found {} entries".format(len(self.compiled))) except Exception as e: self.compiled = [] print("No data found") else: self.compiled = [] print("No data found")
def reply_music(id, code, mcode): try: # Send action "Uploading file" bot.send_chat_action(chat_id=id, action='upload_document') # Receive audio download link temp = get_web(f'{TRACKS_API}/{code}/stream?{SC_API}').url # Receive audio info temp2 = get_json(get_web(f'{TRACKS_API}/{code}?{SC_API}').text) # Send link and desc -> Telegram -> as file + desc to user bot.send_audio( id, audio=temp, reply_markup=generate_markup3(id, mcode), caption=f"{temp2['user']['username']} - {temp2['title']}") except: bot.send_message(id, get_text(id, 'uerror'))
def command_receive(message): id = message.chat.id try: if len(message.text) >= 4 and 'http' not in message.text: bot.clear_step_handler_by_chat_id(id) a = get_json( get_web(f'{TRACKS_API}?q={message.text}&{SC_API}').text) if len(a) <= 1: # No JSON content in reply data bot.send_message(id, get_text(id, 'nfound')) else: # We received JSON search answer bot.send_message(id, get_text(id, 'smusic'), reply_markup=generate_markup(a)) except: bot.send_message(id, get_text(id, 'uerror'))
def reply_by_link(m, del_id): try: # check if link contains SoundCloud start if m.text[:23] == f'https://{SC}/' or m.text[:23] == f'http://{SC}/': # Send action: "Uploading file" bot.send_chat_action(chat_id=m.chat.id, action='upload_document') # Receive track API info info = get_json( get_web(f'http://api.{SC}/resolve?url={m.text}&{SC_API}').text) # Open link to download audio temp = get_web(info['stream_url'] + '?' + SC_API).url # Send this link -> Telegram -> as file to user bot.send_audio(m.chat.id, audio=temp, caption=info['title']) else: # Bad link detected bot.send_message(chat_id=m.chat.id, text=get_text(m.chat.id, 'ulink')) bot.delete_message(chat_id=m.chat.id, message_id=del_id) except: bot.send_message(id, get_text(id, 'uerror'))
def download_json(name): try: with open(name) as algo: return get_json(algo) except FileNotFoundError: raise