def init(): global logger # get secret and proxy config parser = argparse.ArgumentParser() parser.add_argument('--secret', type=str, default='', help="Fateadm secret file") parser.add_argument('--proxy', type=int, help="local proxy port") parser.add_argument('--session', type=str, default="session.json", help="path to save sessions") parser.add_argument('--log_dir', type=str, default="./fast_visa", help="directory to save logs") args = parser.parse_args() # config logging if not os.path.exists(args.log_dir): os.makedirs(args.log_dir) log_path = os.path.join(args.log_dir, "fast_visa.log") logger = logging.getLogger("fast_visa") handler = TimedRotatingFileHandler(log_path, when="midnight", interval=1) handler.suffix = "%Y%m%d" formatter = logging.Formatter( "%(asctime)s [%(filename)s:%(lineno)d] %(levelname)s - %(message)s") handler.setFormatter(formatter) logger.setLevel(logging.INFO) logger.addHandler(handler) logger.info("Initialization...") # config cracker if len(args.secret) == 0: cracker = args cracker.solve = lambda x: input('Captcha: ') else: cracker = Captcha(args.secret, args.proxy) proxies = dict(http='socks5h://127.0.0.1:' + str(args.proxy), https='socks5h://127.0.0.1:' + str(args.proxy)) if args.proxy else None g.assign("proxies", proxies) g.assign("cracker", cracker) # read cached session pool (if any) g.assign("session_file", args.session) session_op.init_cache()
def init(): global logger # get secret and proxy config parser = argparse.ArgumentParser() parser.add_argument('--secret', type=str, default='', help="Fateadm secret file") parser.add_argument('--proxy', type=int, help="local proxy port") parser.add_argument('--session', type=str, default="session.json", help="path to save sessions") parser.add_argument('--log_dir', type=str, default="./fast_visa", help="directory to save logs") args = parser.parse_args() # config logging if not os.path.exists(args.log_dir): os.makedirs(args.log_dir) log_path = os.path.join(args.log_dir, "fast_visa.log") logger = logging.getLogger("fast_visa") handler = TimedRotatingFileHandler(log_path, when="midnight", interval=1) handler.suffix = "%Y%m%d" formatter = logging.Formatter( "%(asctime)s [%(filename)s:%(lineno)d] %(levelname)s - %(message)s") handler.setFormatter(formatter) logger.setLevel(logging.INFO) logger.addHandler(handler) logger.info("Initialization...") # config cracker # if len(args.secret) == 0: # cracker = args # cracker.solve = lambda x: input('Captcha: ') # else: # cracker = Captcha(args.secret, args.proxy) cracker = Captcha() proxies = dict( http='socks5h://127.0.0.1:' + str(args.proxy), https='socks5h://127.0.0.1:' + str(args.proxy) ) if args.proxy else None g.assign("proxies", proxies) g.assign("cracker", cracker) # read cached session pool (if any) g.assign("session_file", args.session) session_op.init_cache() # restore previous data for visa_type in ["F", "B", "H", "O", "L"]: fn = '../visa/visa.json' if visa_type == "F" else '../visa/visa-%s.json' % visa_type.lower() orig = json.loads(open(fn).read()) if os.path.exists(fn) else {} if "time" not in orig: continue date = orig["time"].split()[0] data = {} for k, v in orig.items(): if k.endswith("2-" + date): continue if k.endswith(date): place = k.split("-")[0] if v == "/": y, m, d = 0, 0, 0 else: y, m, d = list(map(int, v.split("/"))) data[place] = (y, m, d) g.assign("status_%s_%s" % (visa_type, place), (y, m, d)) logger.info("%s, Restored date: %s" % (visa_type, str(data)))