def register_client(self, credentials=None, options=None, server_id=None, server_selection=False): client = self.get_client(server_id) self.client = client self.connect_manager = client.auth if server_id is None: client.config.data['app.default'] = True try: state = client.authenticate(credentials or {}, options or {}) if state['State'] == CONNECTION_STATE['SignedIn']: client.callback_ws = event if server_id is None: # Only assign for default server client.callback = event self.get_user(client) settings('serverName', client.config.data['auth.server-name']) settings('server', client.config.data['auth.server']) event('ServerOnline', {'ServerId': server_id}) event('LoadServer', {'ServerId': server_id}) return state['Credentials'] elif (server_selection or state['State'] == CONNECTION_STATE['ServerSelection'] or state['State'] == CONNECTION_STATE['Unavailable'] and not settings('SyncInstallRunDone.bool')): self.select_servers(state) elif state['State'] == CONNECTION_STATE['ServerSignIn']: if 'ExchangeToken' not in state['Servers'][0]: self.login() elif state['State'] == CONNECTION_STATE['Unavailable'] and state['Status_Code'] == 401: # If the saved credentials don't work, restart the addon to force the password dialog to open window('jellyfin.restart', clear=True) elif state['State'] == CONNECTION_STATE['Unavailable']: raise HTTPException('ServerUnreachable', {}) return self.register_client(state['Credentials'], options, server_id, False) except RuntimeError as error: LOG.exception(error) xbmc.executebuiltin('Addon.OpenSettings(%s)' % addon_id()) raise Exception('User sign in interrupted') except HTTPException as error: if error.status == 'ServerUnreachable': event('ServerUnreachable', {'ServerId': server_id}) return client.get_credentials()
print('') option = int(input('Marque la opción que desee: ')) print('') while option != 0: print('') if option == 1: server_ip = str(input('Ingrese la IP del servidor (ej. 127.0.0.1): ')) client_ip = str(input('Ingrese la IP del cliente (ej. 127.0.0.1): ')) tcp_port = int(input('Ingrese el puerto TCP (ej. 19876): ')) udp_port = int(input('Ingrese el puerto UDP (ej. 9876): ')) client.connect(server_ip, client_ip, tcp_port, udp_port) connected = True elif option == 2: user = str(input('Ingrese su usuario: ')) if "invalid" in client.authenticate(user): user = None elif option == 3: msg = client.req_msg() msg_decoded = base64.b64decode(msg) user_msg = msg_decoded.decode('utf-8') print('El mensaje recibido es:', user_msg) elif option == 4: client.req_msg_length() elif option == 5: if msg_decoded: client.validate_msg(msg_decoded) else: print('Primero debe solicitar el mensaje al servidor') elif option == 6: client.logout()
def parse_timetable(): client.authenticate() for sheet in xl_workbook.sheets(): sheet_name = sheet.name days_row_index = get_days(sheet) if "Athi" in sheet_name: client.create_collection("athitt") print("\n" + sheet_name) if sheet.ncols < 14: for row in [x for x in range(3, sheet.nrows)]: for col in [ x for x in range(1, sheet.ncols) if (x != 3) and (x != 8) ]: if sheet.cell(row, col).value: for k in days_row_index.keys(): if col in days_row_index[k]: time = sheet.cell(2, col).value.split('-') body = dict(location=sheet.cell(row, 0).value, start_time=time[0], end_tiem=time[1], day=sheet.cell(1, col).value) title = sheet.cell(row, col).value data = dict(title="".join(title.split()), body=body) client.create_document("athitt", data) # print(sheet.cell(1, col).value+" : "+sheet.cell(row, col).value+" : "+sheet.cell(row, 0).value+" : "+sheet.cell(2, col).value) else: for row in [x for x in range(3, sheet.nrows)]: for col in [ x for x in range(1, sheet.ncols) if (x != 3) and (x != 8) and (x != 9) ]: if sheet.cell(row, col).value: for k in days_row_index.keys(): if col in days_row_index[k]: time = sheet.cell(2, col).value.split('-') body = dict(location=sheet.cell(row, 0).value, start_time=time[0], end_tiem=time[1], day=sheet.cell(1, col).value) title = sheet.cell(row, col).value data = dict(title="".join(title.split()), body=body) client.create_document("athitt", data) # print(sheet.cell(1, col).value+" : "+sheet.cell(row, col).value + " : " + sheet.cell(row, 0).value + " : " + sheet.cell(2,col).value) elif "Day" in sheet_name: client.create_collection("nairobidaytt") print("\n" + sheet_name) for row in [x for x in range(3, sheet.nrows)]: for col in [ x for x in range(1, sheet.ncols) if (x != 5) and (x != 9) and (x != 11) ]: if sheet.cell(row, col).value: for k in days_row_index.keys(): if col in days_row_index[k]: time = sheet.cell(2, col).value.split('-') body = dict(location=sheet.cell(row, 0).value, start_time=time[0], end_tiem=time[1], day=sheet.cell(1, col).value) title = sheet.cell(row, col).value data = dict(title="".join(title.split()), body=body) client.create_document("nairobidaytt", data) # print(sheet.cell(1, col).value+" : "+sheet.cell(row, col).value+" : "+sheet.cell(row, 0).value+" : "+sheet.cell(2, col).value) elif "Evening" in sheet_name: client.create_collection("nairobieveningtt") print("\n" + sheet_name) for row in [x for x in range(3, sheet.nrows)]: for col in [x for x in range(1, sheet.ncols) if (x != 5)]: if sheet.cell(row, col).value: for k in days_row_index.keys(): if col in days_row_index[k]: time = sheet.cell(2, col).value.split('-') body = dict(location=sheet.cell(row, 0).value, start_time=time[0], end_tiem=time[1], day=sheet.cell(1, col).value) title = sheet.cell(row, col).value data = dict(title="".join(title.split()), body=body) client.create_document("nairobieveningtt", data)
def check_match(self, user, key): return authenticate(user, key)