def find_accounts(): temp_ban_time = datetime.datetime.now() - datetime.timedelta(days=35) warn_time = datetime.datetime.now() - datetime.timedelta(days=20) perm_ban_time = datetime.datetime.now() - datetime.timedelta(days=60) blind_time = datetime.datetime.now() - datetime.timedelta(days=30) pool = ThreadPoolExecutor( thread_count(args)) # for many urls, this should probably be allocatable = db_find_allocatable_by_level(temp_ban_time, perm_ban_time, warn_time, blind_time, datetime.datetime.now(), args.min_level, args.max_level) requred_accounts = int(args.count) futures = [] account_iter = iter(allocatable) def next_account(): return account_manager.add_account(next(account_iter)) location = location_parse(args.location) result = [] if args.no_login: for i in range(0, requred_accounts): result.append(next_account()) else: for idx in range(0, requred_accounts): futures.append( pool.submit(lambda: check_worker_for_future( next_account(), account_manager, location_to_use=location)) ) future_pos = 0 while len(result) < requred_accounts: if future_pos > len(futures): raise AssertionError( "This should not happen, maybe previous error is making it happen" ) r = futures[future_pos].result() if r[0]: result.append(r[1]) log.info("{} of {} found".format(str(len(result)), str(requred_accounts))) else: db_roll_allocated_date_forward(r[1]) futures.append( pool.submit(lambda: check_worker_for_future( next_account(), account_manager, location_to_use=location))) future_pos += 1 return result
def f_get(position): pos = location_parse(position) log.info("Received request for {}".format(str(pos))) if pos is None: return "Missing coordinates. Ensure page has location access and use a proper browser (safari/chromet etc, not the facebook browser)" the_thread = berry_location( loc, FeedWorker(account_manager, termination_condition, args.trainers, False, True)) threads.append(the_thread) return "Starting at {}, be a little patitent ".format(str(pos))
def f_get(position): pos = location_parse(position.strip()) log.info(u"Received request for {}".format(str(pos))) if pos is None: return "Missing coordinates. Ensure page has location access and use a proper browser (safari/chromet etc, not the facebook browser)" asyncio.set_event_loop(loop) feed_worker = FeedWorker(account_manager, termination_condition, args.trainers, False, True) asyncio.ensure_future(safe_berry_one_position(pos, feed_worker)) return "Starting at {}, be a little patitent ".format(str(pos))
def safe_lure_one_json_worker(json_location, route_section, counter): while True: start = json_location["start"] end = json_location["end"] name_ = json_location["name"] days = json_location["days"] if is_blank(days): log.info("No days sceheduled for {}, terminating thread".format(name_)) return start_at = start_at_datetime(start) stop_time = stop_at_datetime(start, end) now = datetime.now() if not will_start_now(json_location): if after_stop(json_location): sleep_dur = ((start_at + timedelta(days=1)) - now).total_seconds() else: sleep_dur = (start_at - now).total_seconds() log.info("Sleeping for {}".format(str(sleep_dur))) if sleep_dur < 0: sleep_dur = abs(sleep_dur) log.info("{} outside running period from {} until {}, sleeping {} seconds".format(name_, start_at, stop_time, sleep_dur)) time.sleep(sleep_dur) weekday = str(datetime.today().weekday()) if weekday not in days: tomorrow = datetime.now() + timedelta(days=1) tomorrow_morning = tomorrow.replace(hour=0, minute=1) seel_dur = (tomorrow_morning - now).total_seconds() log.info("Not today, waiting {} seconds until tomorrow".format(seel_dur)) time.sleep(seel_dur) else: log.info("{} running until {}".format(name_, stop_time)) try: ld = LureWorker(account_manager, fix_branding, lambda lure_dropped: datetime.now() < stop_time, counter, args.lure_duration) as_coordinates = [location_parse(x) for x in route_section] ld.lure_json_worker_positions(as_coordinates) time.sleep(60) except OutOfAccounts: log.warn("No more accounts, exiting") return except Exception as e: log.exception(e) time.sleep(12)
def lure_bomb_get(user, position, minutes, radius=50): parsed = location_parse(position) pos = with_gmaps_altitude(parsed, args.gmaps_key) log.info("Received luring request for {} at {} for {} minutes".format(user, str(pos), str(minutes))) lures1 = lures(user) if len(lures1) == 0: abort(404) if pos is None: return "Missing coordinates for luring. Ensure page has location access and use a proper browser (safari/chromet etc, not the facebook browser)" max_lures = lures1[0]["max_lures"] current_lures = lures1[0].get("lures", 0) remaining_lures = max_lures - current_lures if max_lures <= current_lures: return "All {} lures are spent".format(lures1.max_lures) ld = LureWorker(account_manager, fix_branding, should_continue(int(minutes)), DbLureCounter(user), args.lure_duration) a_thread = Thread(target=lambda: ld.lure_bomb(pos, radius)) a_thread.start() db_move_to_levelup(args.system_id, "forlevelup") db_move_to_trash(args.system_id, "trash") return "<h2>Luring at {}, be a little patitent. You have {} lures left</h2>".format(str(pos), str(remaining_lures))
def add_gmaps_altitude(args, locations): return [ with_gmaps_altitude(location_parse(x), args.gmaps_key) for x in locations.strip().split(' ') ]
def proceed(worker): info = worker.account_info() warning_ = info["warning"] level = info["level"] eggs = egg_count(worker) lures = lure_count(worker) db_set_logged_in_stats(info.username, lures, eggs, level) log.info("{} level {}, {} lures {} eggs".format(worker.name(), level, lures, eggs)) if warning_: db_set_warned(info, datetime.datetime.now()) return False location = location_parse(args.location) def check_account(delay): wrapped = wrap_accounts_minimal(account_manager.get_account(False), account_manager) try: time.sleep(delay) return wrapped.login(location, proceed) except LoginSequenceFail: db_set_perm_banned(wrapped.account_info(), datetime.datetime.now()) except TooManyLoginAttempts: db_set_perm_banned(wrapped.account_info(), datetime.datetime.now()) except AccountBannedException: db_set_temp_banned(wrapped.name(), datetime.datetime.now()) except Exception:
FeedWorker(account_manager, termination_condition, args.trainers, False, True)) threads.append(the_thread) return "Starting at {}, be a little patitent ".format(str(pos)) def run_server(): app.run(threaded=True, host=args.host, port=args.port) if args.port: the_thread = Thread(name="FServer", target=run_server) the_thread.start() locs = [ with_gmaps_altitude(location_parse(x), args.gmaps_key) for x in args.locations.strip().split(' ') ] position = locs[0] args.player_locale = gmaps_reverse_geolocate( args.gmaps_key, args.locale, str(position[0]) + ', ' + str(position[1])) account_manager = AccountManager(args.system_id, True, args, [], [], Queue(), {}) account_manager.initialize(args.accountcsv, ()) stop_at = None if args.stop_at: stop_at = stop_at_datetime(args.stop_at) msg = "Stopping at {}".format(str(stop_at))