def _create_rule(self, from_chat, to_chat): info_from_chat = info(from_chat) if info_from_chat is None: sender.msg(self._admin['id'], from_chat + " no existe") sender.msg(self._admin['id'], "Puedes obtener una lista de los chat disponibles diciendo \"dialogos\" \"canales\" o \"contactos\"") return info_to_chat = info(to_chat) if info_to_chat is None: sender.msg(self._admin['id'], to_chat + " no existe") sender.msg(self._admin['id'], "Puedes obtener una lista de los chat disponibles diciendo \"dialogos\" \"canales\" o \"contactos\"") return return ForwardRule(info_from_chat['id'], info_to_chat['id'])
def authorize(client_id, client_secret, config): """ A module method to authorize Spotify using a OAuth client ID and client secret. """ state = util.random_string(14) scope = 'playlist-modify-private' authorization_url = '{}?client_id={}&response_type=code'.format( REQUEST_TOKEN_URL, client_id ) authorization_url += '&redirect_uri={}&state={}&scope={}'.format( CALLBACK_URI, state, scope ) if config.verbose: util.debug('Authorization URL constructed: {}'.format(authorization_url)) # Prompt the user to authorize via a browser: util.info('Now opening a browser to authorize your Spotify account.') util.info('Once authorized, copy/paste the URL of that browser window here.') util.info('Finally, hit enter to complete the auhtorization process.') util.confirm('Do you want to continue?') util.open_url(authorization_url) # Deal with the return code: authorization_response = util.prompt('Enter the URL', None) parsed = urlparse.urlparse(authorization_response) authorization_args = urlparse.parse_qs(parsed.query) if config.verbose: util.debug('Authorization arguments: {}'.format(authorization_args)) # Check to make sure the states between request and response match: if state == authorization_args.get('state')[0]: if 'code' in authorization_args: # The authorization succeeded: params = { 'client_id': client_id, 'client_secret': client_secret, 'grant_type': 'authorization_code', 'code': authorization_args.get('code')[0], 'redirect_uri': CALLBACK_URI } r = requests.post(ACCESS_TOKEN_URL, data=params) if config.verbose: util.debug('Access response: {}'.format(r.content)) return r.json() else: # The authorization failed: if 'error' in authorization_args: raise music_service.AuthorizationError(authorization_args.get('error')[0]) else: raise music_service.AuthorizationError('unknown authorization error') else: raise SpotifyStateError()
def authorize(client_id, client_secret, config): # Get the resource OAuth keys: oauth = OAuth1(client_id, client_secret=client_secret, callback_uri=CALLBACK_URI) r = requests.post(url=REQUEST_TOKEN_URL, auth=oauth) if config.verbose: util.debug('Request token response: {}'.format(r.content)) credentials = urlparse.parse_qs(r.content) if credentials: # If the token request worked, proceed: resource_owner_key = credentials.get('oauth_token')[0] resource_owner_secret = credentials.get('oauth_token_secret')[0] authorize_url = BASE_AUTHORIZATION_URL + '?oauth_token=' authorize_url = authorize_url + resource_owner_key if config.verbose: util.debug('Authorization URL constructed: {}'.format(authorize_url)) util.info('Now opening a browser to authorize your Beatport account.') util.info('Once authorized, copy/paste the URL of that browser window here.') util.info('Finally, hit enter to complete the auhtorization process.') util.confirm('Do you want to continue?') util.open_url(authorize_url) # Deal with the return code: authorization_response = util.prompt('Enter the URL', None) parsed = urlparse.urlparse(authorization_response) authorization_args = urlparse.parse_qs(parsed.query) verifier = authorization_args.get('oauth_verifier')[0] if config.verbose: util.debug('Authorization arguments: {}'.format(authorization_args)) # Finally, get the access tokens: oauth = OAuth1(client_id, client_secret=client_secret, resource_owner_key=resource_owner_key, resource_owner_secret=resource_owner_secret, verifier=verifier) r = requests.post(url=ACCESS_TOKEN_URL, auth=oauth) if config.verbose: util.debug('Access response: {}'.format(r.content)) return urlparse.parse_qs(r.content) else: raise service.AuthorizationError('Invalid client ID and client secret...')
# normal = -1*direction # old_vel = [] # for v_axis in string: # old_vel.append(fluid_collider[v_axis]) # new_vel = old_vel - (1+c_R*d/(delta_t*mag_old_vel))*dot(old_vel,normal)*normal # count = 0 # for v_axis in string: # moving[colliders[i][0]][v_axis] = new_vel[count] * lam_v * fluid_radius*2 /max(new_vel) # moving[colliders[i][0]][v_axis[0]] = moving[colliders[i][0]][v_axis[0]] + lam_v * fluid_radius*2 /max(new_vel) * new_vel[count] # count += 1 time = time + delta_t iteration = iteration + 1 correction = False if iteration % w == 0: correction = True #Saving iterations utilities.save_csv(paths[2],iteration,{key: particles[key] for key in fluid_array}) utilities.save_moving_vtk(paths[0],iteration,{key: particles[key] for key in fluid_array}) #Making vtk group utilities.add_to_group(paths[0],iteration,time,paths[1]) with open(paths[0].replace("/vtk","/time.txt"), "a") as f: f.write(str(time) + "\n") utilities.info(time,final_time,start_time,tm.time(),delta_t,iteration) utilities.save_group(paths[1])
criteria_1 = 0.2 * sqrt(h / max_force) < delta_t except: criteria_1 = False criteria_2 = max_rho_err > 5.5 * density_fluctuation_permited criteria_3 = mean(density_error_array) >= density_fluctuation_permited try: criteria_4 = 0.4 * h / max_vel <= delta_t except: criteria_4 = False if criteria_1 or criteria_2 or criteria_3 or criteria_4: delta_t -= 0.002 * delta_t if time + delta_t > final_time: delta_t = final_time - time #Saving iterations utilities.save_csv(paths[2], iteration, {key: particles[key] for key in fluid_array}) utilities.save_moving_vtk(paths[0], iteration, {key: particles[key] for key in fluid_array}) #Making vtk group utilities.add_to_group(paths[0], iteration, time, paths[1]) with open(paths[0].replace("/vtk", "/time.txt"), "a") as f: f.write(str(time) + "\n") utilities.info(time, final_time, start_time, tm.time(), delta_t, iteration, max_rho_err) utilities.save_group(paths[1])
def __repr__(self): from_info = info(self._from_chat) to_info = info(self._to_chat) # print(from_info) # print(to_info) return "De " + from_info["print_name"] + " a " + to_info["print_name"]
def __str__(self): from_info = info(self._from_chat) to_info = info(self._to_chat) # print(from_info) # print(to_info) return from_info["print_name"] + " " + to_info["print_name"]
STYLE.CODEBLOCK_CLASS, "fore:#4ec9b0,back:#282828,face:%(mono)s,size:%(size)d" % faces) self.edit.StyleSetSpec( STYLE.CODEBLOCK_TYPE, "fore:#EFCD1E,back:#282828,face:%(mono)s,size:%(size)d" % faces) self.edit.StyleSetSpec( STYLE.CODEBLOCK_FLOW, "fore:#d8a0df,back:#282828,face:%(mono)s,size:%(size)d" % faces) self.edit.StyleSetSpec( STYLE.CODEBLOCK_DIGIT, "fore:#b5ce92,back:#282828,face:%(mono)s,size:%(size)d" % faces) self.edit.IndicatorSetStyle(0, stc.STC_INDIC_SQUIGGLE) self.edit.IndicatorSetForeground(0, wx.RED) def onClose(self, event): """ Runs when the application is being closed:\n * Removes the temporary html file and closes the application. """ os.remove(self.html) sys.exit() if __name__ == '__main__': start = time.time() app = wx.App() frm = Application(None) end = time.time() util.info(f"Application load time: {round(end - start, 2)}s") app.MainLoop()