def load_orjson(file, data): import orjson if file is not None: return orjson.load(file) with open(data, 'r') as f: return orjson.load(f)
def load_orjson(file, data): import orjson if file is not None: args['verbose'] and print(f"Loading file using orjson") return orjson.load(file) with open(data, 'r') as f: return orjson.load(f)
def query_stock(): with open(STOCK_FILE) as stock_io: stock = json.load(stock_io) stock = [s['id'] for s in stock if '/' not in s['id']] with requests.Session() as session: session.auth = AUTH for chunk in [stock[i:i + 5] for i in range(0, len(stock), 5)]: stock_list = ','.join(chunk[:5]) url = f'{URL}/feed/{stock_list}/last' pprint(url) response = session.get(url=url, data={'level': 'best_price'}) assert response.status_code == 200, response.text pprint(response.json())
def main(argv): parser = argparse.ArgumentParser() parser.add_argument('--network', '-n', type=str, default='byoda.net') parser.add_argument('--root-directory', '-r', type=str, default=_ROOT_DIR) parser.add_argument('--service_id', '-s', type=str, default='4294929430') parser.add_argument('--password', '-p', type=str, default='byoda') parser.add_argument('--tempdir', '-t', type=str, default='/tmp') parser.add_argument('--data-file', '-f', type=str, default='data.json') args = parser.parse_args() with open(args.data_file) as file_desc: data = orjson.load(file_desc) root_dir = args.root_directory network_dir = f'{root_dir}/network-{args.network}' account_dir = f'{network_dir}/account-pod' member_dir = f'{account_dir}/service-{args.service_id}' root_ca_cert = f'{network_dir}/network-{args.network}-root-ca-cert.pem' account_cert_file = f'{account_dir}/pod-cert.pem' member_cert_file = (f'{member_dir}/network-{args.network}-' f'member-{args.service_id}-cert.pem') unprotected_key = decrypt_private_key(args) fqdn = get_cert_fqdn(member_cert_file) graphql_url = f'https://{fqdn}/api/v1/data/service-{args.service_id}' client = GraphqlClient(endpoint=graphql_url, verify=root_ca_cert, cert=(member_cert_file, unprotected_key)) result = client.execute(query=MUTATE_PERSON.format( given_name=data['person']['given_name'], additional_names=data['person']['additional_names'], family_name=data['person']['family_name'], email=data['person']['email'], homepage_url=data['person']['homepage_url'], avatar_url=data['person']['avatar_url'])) if 'data' in result: print(f'Data returned by GraphQL: {result["data"]}')
logger.fatal(response_raw.text) logger.fatal(e) return False return response if __name__ == '__main__': # IMPORTATIONS import logging from degiro_connector.trading.pb.trading_pb2 import Credentials # FETCH CONFIG with open('config.json') as config_file: config = json.load(config_file) # SETUP CREDENTIALS username = config['username'] password = config['password'] int_account = config['int_account'] credentials = Credentials(int_account=int_account, username=username, password=password) # SETUP LOGS log_level = logging._nameToLevel['INFO'] log_level = logging.getLevelName(log_level) logging.basicConfig( level=log_level, format='%(asctime)s %(levelname)-8s %(message)s',
import orjson import numpy as np import sys from poke_env.data import POKEDEX from poke_env.player.random_player import RandomPlayer from poke_env.player_configuration import PlayerConfiguration from poke_env.server_configuration import LocalhostServerConfiguration from poke_env.teambuilder.teambuilder import Teambuilder from poke_env.teambuilder.teambuilder_pokemon import TeambuilderPokemon from poke_env.utils import to_id_str from tqdm import tqdm with open("src/poke_env/data/learnset.json") as f: movesets = orjson.load(f) print("-" * 20, "\n") mons = [mon for mon in POKEDEX] def random_evs(): evs = np.random.randint(0, 252, size=6) if sum(evs) > 510: evs = evs / sum(evs) * 510 evs = evs.astype(np.int16) return evs def random_mon(): mon = np.random.choice(mons)