def main(): """main function""" field = { 'minLngE6': 115513544, 'minLatE6': 39532744, 'maxLngE6': 117360226, 'maxLatE6': 40405559, } conn = sqlite3.connect('ingrex.db') c = conn.cursor() # Create table c.execute('''CREATE TABLE IF NOT EXISTS `message` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `timestamp` INTEGER NOT NULL, `text` TEXT NOT NULL, `guid` TEXT NOT NULL, `team` TEXT NOT NULL );''') c.execute('''CREATE TABLE IF NOT EXISTS `mints` ( `id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, `mints` INTEGER NOT NULL );''') conn.commit() logging.basicConfig(filename='ingrex.log', level=logging.DEBUG) with open('cookies') as cookies: cookies = cookies.read().strip() mints = -1 while True: intel = ingrex.Intel(cookies, field) result = intel.fetch_msg(mints=-1, maxts=mints) if result: mints = result[-1][1] - 1 print(mints) c.execute('INSERT INTO mints(`mints`) VALUES (?)', (mints, )) conn.commit() for item in reversed(result[::-1]): message = ingrex.Message(item) print(u'{} {}'.format(message.time, message.text)) c.execute( 'INSERT INTO message(`timestamp`, `text`, `guid`, `team`) VALUES (?, ?, ?, ?)', ( message.timestamp, message.text, message.guid, message.team, )) conn.commit() time.sleep(2)
def getIntel(db, conf): ''' try to connect intel map with cookie if cookie is invalid, use usr, pwd return Ingrex.intel object ''' cookie = conf['cookie'] field = { 'minLngE6': conf['minLngE6'], 'maxLngE6': conf['maxLngE6'], 'minLatE6': conf['minLatE6'], 'maxLatE6': conf['maxLatE6'], } try: return ingrex.Intel(cookie, field) except IndexError: usr = conf['account'] pwd = conf['password'] cookie = ingress.login(usr, pwd) setConfig(db, 'cookie', cookie) return ingrex.Intel(cookie, field)
def main(): "main function" field = { 'minLngE6': 116298171, 'minLatE6': 39986831, 'maxLngE6': 116311303, 'maxLatE6': 39990941, } with open('cookies') as cookies: cookies = cookies.read().strip() intel = ingrex.Intel(cookies, field) result = intel.fetch_msg(tab='faction') result = intel.fetch_map(['17_29630_13630_0_8_100']) result = intel.fetch_portal(guid='ac8348883c8840f6a797bf9f4f22ce39.16') result = intel.fetch_score() result = intel.fetch_region() result = intel.fetch_artifacts() print(result)
def main(): "main function" field = { 'minLngE6': 116298171, 'minLatE6': 39986831, 'maxLngE6': 116311303, 'maxLatE6': 39990941, } with open('cookies') as cookies: cookies = cookies.read().strip() mints = -1 while True: intel = ingrex.Intel(field, cookies) result = intel.fetch_msg(mints) if result: mints = result[0][1] + 1 for item in result[::-1]: message = ingrex.Message(item) print(u'{} {}'.format(message.time, message.text)) time.sleep(10)
def main(): logger = logging.getLogger(__name__) # Lat & Lng of fetch region field = { 'minLngE6': minLngE6, 'minLatE6': minLatE6, 'maxLngE6': maxLngE6, 'maxLatE6': maxLatE6, } mints = -1 maxts = -1 reverse = False tab = 'all' # fetch cookie while True: try: if fetch_cookie(): break except CookieException: logger.error(get_time() + ': Fetch Cookie Failed') time.sleep(3) except: logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0]) + " Line: " + str(inspect.currentframe().f_lineno)) time.sleep(3) # fetch message count = 0 while True: count += 1 logger.info(get_time() + ": {} Fetching from Intel...".format(str(count))) with open('cookie') as cookies: cookies = cookies.read().strip() # fetch message per time while True: try: intel = ingrex.Intel(cookies, field) result = intel.fetch_msg(mints, maxts, reverse, tab) if result: mints = result[0][1] + 1 break except: logger.error(get_time() + ": Unexpected error: " + str(sys.exc_info()[0]) + " Line: " + str(inspect.currentframe().f_lineno)) time.sleep(3) for item in result[::-1]: # Check spam message pattern = re.compile(BlockList) match = pattern.search(str(item)) if match: continue message = ingrex.Message(item) if message.ptype == 'PLAYER_GENERATED': if find_message_record(message.guid) is False: insert_message_to_database(message.time, message.guid, message.msg) send_message(bot, message.msg, False) time.sleep(10)
def main(): "main function" islocal = False d = xmlReader() tdelta = d.gettimedelta() cur_time = datetime.utcfromtimestamp(time.time()) + timedelta(hours=tdelta) cur_time = cur_time.strftime('%Y-%m-%d %H:%M:%S') print('{} -- Start Logging...'.format(cur_time)) if islocal is False: reload(sys) sys.setdefaultencoding('utf-8') field = d.getfieldrange() mints = get_max_timestamp() maxts = int(time.time() * 1000) l_mints = maxts print('The overall timestamp duration is {}~{}.'.format(mints, maxts)) result = '' s = requests.Session() with open(d.getcookiepath(islocal=islocal)) as cookies: cookies = cookies.read().strip() intel = ingrex.Intel(cookies, field, s) update_maxts(int(maxts)) while True: result = intel.fetch_msg(mints=int(mints), maxts=int(maxts)) if result: for item in result[::-1]: message = ingrex.Message(item) ts = int(message.timestamp) if ts <= l_mints: l_mints = ts print('{} {} {}'.format(message.time, message.team, message.text)) if message.player_action.strip() in d.getactions(): insert_comm(message) portal_guid = fetch_portal_guid(message) if portal_guid == "": insert_for_update(message) else: portal_raw = intel.fetch_portal(guid=portal_guid) portal = ingrex.Portal(portal_raw, fromdetail=True) if message.player_action.strip() == 'captured': update_capture_status(message, portal) else: update_capture_status(message, portal, iscapture=False) print('Fetched {} comm logs during the timestamp period {}~{}.'. format(len(result), int(l_mints), int(maxts))) print('+' * 80) else: print('No result can be fetched during the period {}~{}. Exit...'. format(mints, maxts)) break if len(result) < 50: break if mints != l_mints: mints, maxts = mints, l_mints - 1 else: break time.sleep(20) print('-' * 80)