def init_config(): parser = ArgumentParser() load = {} # Read passed in Arguments parser.add_argument("-cf", "--config", help="Configuration file",default=None) parser.add_argument("-a", "--auth_service", help="Auth Service ('ptc' or 'google')") parser.add_argument("-u", "--username", help="Username") parser.add_argument("-p", "--password", help="Password") parser.add_argument("-l", "--location", help="Location") parser.add_argument("-s", "--spinstop", help="SpinPokeStop", action='store_true') parser.add_argument("-v", "--stats", help="Show Stats and Exit", action='store_true') parser.add_argument("-w", "--walk", help="Walk instead of teleport with given speed (meters per second, e.g. 2.5)", type=float, default=2.5) parser.add_argument("-c", "--cp",help="Set CP less than to transfer(DEFAULT 100)",default=100) parser.add_argument("-k", "--gmapkey",help="Set Google Maps API KEY",type=str,default=None) parser.add_argument("--maxsteps",help="Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)",type=int,default=5) parser.add_argument("-d", "--debug", help="Debug Mode", action='store_true') parser.add_argument("-t", "--test", help="Only parse the specified location", action='store_true') parser.add_argument("-tl", "--transfer_list", help="Transfer these pokemons regardless cp(pidgey,drowzee,rattata)", type=str, default='') parser.set_defaults(DEBUG=False, TEST=False) config = parser.parse_args() if config.config and config.config is not 'false': default_config = "config.json" if isfile(config.config): print '[x] Loading configuration file : ' + config.config with open(config.config) as data: load.update(read_json(data)) else: print '[x] Loading default configuration file' with open(default_config) as data: load.update(read_json(data)) else: if config.auth_service is None \ or config.username is None \ or config.password is None \ or config.location is None: parser.error('without -cf <true|filename.json>, (-a <auth_service> -u <username> -p <password> -l <location>) are required') return None # Passed in arguments shoud trump for key in config.__dict__: if key in load: config.__dict__[key] = load[key] if config.auth_service not in ['ptc', 'google']: logging.error("Invalid Auth service ('%s') specified! ('ptc' or 'google')", config.auth_service) return None return config
def init_config(): parser = ArgumentParser() config_file = "config.json" # If config file exists, load variables from json load = {} if isfile(config_file): with open(config_file) as data: load.update(read_json(data)) # Read passed in Arguments required = lambda x: not x in load parser.add_argument( "-a", "--auth_service", help="Auth Service ('ptc' or 'google')", required=required("auth_service") ) parser.add_argument("-u", "--username", help="Username", required=required("username")) parser.add_argument("-p", "--password", help="Password", required=required("password")) parser.add_argument("-l", "--location", help="Location", required=required("location")) parser.add_argument("-s", "--spinstop", help="SpinPokeStop", action="store_true") parser.add_argument("-v", "--stats", help="Show Stats and Exit", action="store_true") parser.add_argument( "-w", "--walk", help="Walk instead of teleport with given speed (meters per second, e.g. 2.5)", type=float, default=2.5, ) parser.add_argument("-c", "--cp", help="Set CP less than to transfer(DEFAULT 100)", default=100) parser.add_argument("-k", "--gmapkey", help="Set Google Maps API KEY", type=str, default=None) parser.add_argument( "--maxsteps", help="Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)", type=int, default=5, ) parser.add_argument("-d", "--debug", help="Debug Mode", action="store_true") parser.add_argument("-t", "--test", help="Only parse the specified location", action="store_true") parser.add_argument( "-tl", "--transfer_list", help="Transfer these pokemons regardless cp(pidgey,drowzee,rattata)", type=str, default="", ) parser.set_defaults(DEBUG=False, TEST=False) config = parser.parse_args() # Passed in arguments shoud trump for key in config.__dict__: if key in load and config.__dict__[key] is None: config.__dict__[key] = load[key] if config.auth_service not in ["ptc", "google"]: logging.error("Invalid Auth service ('%s') specified! ('ptc' or 'google')", config.auth_service) return None return config
def parse_json(self): with open('json/messages.json') as msg_fd: msg_dict = read_json(msg_fd) self.greetings = msg_dict['greetings'] self.thanks = msg_dict['thanks'] self.subjects = msg_dict['subjects'] self.methods = msg_dict['methods'] self.codes = msg_dict['codes']
def get_data_from_json(url): """ Gets data from json at url. """ opener = request.build_opener() try: return read_json(opener.open(url).read().decode("utf8")) except HTTPError: return None
def build_subject_board(self): with open('json/subjects.json') as msg_fd: self.brd_dict = read_json(msg_fd) subj_list = self.brd_dict['subjects'] self.subjects = keyboard(True, True) i = 0 while i < len(subj_list)-1 and i < 6: self.subjects.row(subj_list[i], subj_list[i+1]) i += 2 if len(subj_list) % 2: self.subjects.row(subj_list[i]) self.subjects.row('Поддержать')
def _read_table_from_source(source: Union[pd.DataFrame, str], chunk_size: int, max_workers: int) -> str: """ Infers a data source type (path or Pandas DataFrame) and reads it in as a PyArrow Table. The PyArrow Table that is read will be written to a parquet file with row group size determined by the minimum of: * (table.num_rows / max_workers) * chunk_size The parquet file that is created will be passed as file path to the multiprocessing pool workers. Args: source (Union[pd.DataFrame, str]): Either a string path or Pandas DataFrame. chunk_size (int): Number of worker processes to use to encode values. max_workers (int): Amount of rows to load and ingest at a time. Returns: str: Path to parquet file that was created. """ # Pandas DataFrame detected if isinstance(source, pd.DataFrame): table = pa.Table.from_pandas(df=source) # Inferring a string path elif isinstance(source, str): file_path = source filename, file_ext = os.path.splitext(file_path) if ".csv" in file_ext: from pyarrow import csv table = csv.read_csv(filename) elif ".json" in file_ext: from pyarrow import json table = json.read_json(filename) else: table = pq.read_table(file_path) else: raise ValueError( f"Unknown data source provided for ingestion: {source}") # Ensure that PyArrow table is initialised assert isinstance(table, pa.lib.Table) # Write table as parquet file with a specified row_group_size tmp_table_name = f"{int(time.time())}.parquet" row_group_size = min(int(table.num_rows / max_workers), chunk_size) pq.write_table(table=table, where=tmp_table_name, row_group_size=row_group_size) # Remove table from memory del table return tmp_table_name
def read(raw_dd, raw_fse): dd_data = [json.read_json(dd_data) for dd_data in raw_dd] fse_data = [json.read_json(fse_data) for fse_data in raw_fse] return dd_data, fse_data
# If config file exists, load variables from json load = {} <<<<<<< HEAD if isfile(config_file): ======= # Select a config file code parser.add_argument("-cf", "--config", help="Config File to use") config_arg = unicode(parser.parse_args().config) if os.path.isfile(config_arg): with open(config_arg) as data: load.update(json.load(data)) elif os.path.isfile(config_file): >>>>>>> upstream/master with open(config_file) as data: load.update(read_json(data)) # Read passed in Arguments required = lambda x: not x in load <<<<<<< HEAD parser.add_argument("-a", "--auth_service", help="Auth Service ('ptc' or 'google')", required=required("auth_service")) parser.add_argument("-u", "--username", help="Username", required=required("username")) parser.add_argument("-p", "--password", help="Password", required=required("password")) parser.add_argument("-l", "--location", help="Location", required=required("location")) parser.add_argument("-s", "--spinstop", help="SpinPokeStop", action='store_true') parser.add_argument("-v", "--stats", help="Show Stats and Exit", action='store_true') parser.add_argument("-w", "--walk", help="Walk instead of teleport with given speed (meters per second, e.g. 2.5)", type=float, default=2.5) parser.add_argument("-c", "--cp", help="Set CP less than to transfer(DEFAULT 100)", type=int, default=100) parser.add_argument("-k", "--gmapkey",help="Set Google Maps API KEY",type=str,default=None) parser.add_argument("--maxsteps",help="Set the steps around your initial location(DEFAULT 5 mean 25 cells around your location)",type=int,default=5)
def schedule_by_classnum(term, classnum): course = uwaterloo.courses(classnum)('schedule.json') response = course.GET(params=dict(params.items() + [('term', term)])) return read_json(response.text)['data']