def main():
    "main function"
    d = xmlReader()
    tdelta = d.gettimedelta()
    cur_time = datetime.utcfromtimestamp(time.time()) + timedelta(hours=tdelta)
    print(cur_time.strftime('%Y-%m-%d %H:%M:%S'),
          '-- Start calculate tile keys...')
    r = ""
    try:
        query_select = d.getquery(name="select_coor_to_calculate")
        dbinfo = d.getdbinfo()
        db = pymysql.connect(**dbinfo)
        cursor = db.cursor()
        cursor.execute(query_select)
        r = cursor.fetchall()
    except Exception as e:
        raise e
    finally:
        cursor.close()
        db.close()

    if r:
        for result in r:
            field = {
                'minLngE6': int(result[0]),
                'minLatE6': int(result[1]),
                'maxLngE6': int(result[0]),
                'maxLatE6': int(result[1]),
            }

            xtile, ytile = ingrex.Utils.calc_tile(field['minLngE6'] / 1E6,
                                                  field['minLatE6'] / 1E6, 15)
            tilekey = d.gettilekeyformat().format(xtile, ytile)

            try:
                query_update = d.getquery(name="calculate_tilekey").format(
                    tilekey, result[0], result[1])
                db = pymysql.connect(**dbinfo)
                cursor = db.cursor()
                cursor.execute(query_update)
                db.commit()
                print('Tilekey[{}] is updated.'.format(tilekey))
            except Exception as e:
                print(query_update)
                raise e
            finally:
                if cursor:
                    cursor.close()
                if db:
                    db.close()
    else:
        print('No record is found to calculate tilekey.')
    print('-' * 80)
Beispiel #2
0
def main():
    "main function"
    islocal = True
    d = xmlReader()
    tdelta = d.gettimedelta()
    cur_time = datetime.utcfromtimestamp(time.time()) + timedelta(hours=tdelta)
    print(cur_time.strftime('%Y-%m-%d %H:%M:%S'), '-- Start insert portal list.')
    if islocal is False:
        reload(sys)
        sys.setdefaultencoding('utf-8')
    field = d.getfieldrange()
    s = requests.Session()
    tilekeys = get_tile_keys()
    if len(tilekeys) > 0:
        for i in range(0, len(tilekeys)):
            if i >= 30:
                print('Tilekey list is too long. Only select 30 tilekeys to process...')
                break
            key = tilekeys[i]
            tilekey = key[0]
            print(tilekey)
            with open(d.getcookiepath(islocal=islocal)) as cookies:
                cookies = cookies.read().strip()
            intel = Intel(cookies, field, s)
            result = intel.fetch_map([tilekey])
            entities = result['map'][tilekey]['gameEntities']
            try:
                for entity in entities:
                    if entity[0][-3:] in d.getentityendings():
                        portal = ingrex.Portal(entity)
                        insert_portal_from_tile(portal)
            except Exception as e:
                update_tile_sync_status(tilekey, syncfail=True)
                print(e)
            else:
                update_tile_sync_status(tilekey)
            time.sleep(60)
    else:
        print('No tilekey to be fetched.')
    print('-' * 80)
Beispiel #3
0
import requests, re, time, json
import lxml
from bs4 import BeautifulSoup as bs
from requests.utils import cookiejar_from_dict
from datetime import datetime, timedelta
from ingrex.xmlReader import xmlReader

islocal = False
d = xmlReader()
tdelta = d.gettimedelta()
cur_time = datetime.utcfromtimestamp(time.time()) + timedelta(hours=tdelta)
print(cur_time.strftime('%Y-%m-%d %H:%M:%S'), '-- Start verify cookie status.')

with open(d.getcookiepath(islocal=islocal)) as cookie:
    cookie = cookie.read().strip()
print('Before refresh:')
print(cookie)
cookie_dict = {}
googleaccount = d.getgoogleaccount()
username, password = googleaccount['username'], googleaccount['password']

lst_keys = []
lst_values = []
lst_cookies = cookie.split(";")
for lst_cookie in lst_cookies:
    lst_keys.append(lst_cookie.split("=")[0].strip())
    lst_values.append(lst_cookie.split("=")[1].strip())
cookie_dict = dict(zip(lst_keys, lst_values))
cookie_dict.pop('SACSID')

try:
Beispiel #4
0
def get_query(name):
    d = xmlReader()
    return d.getquery(name)
Beispiel #5
0
def connect_to_db():
    d = xmlReader()
    dbinfo = d.getdbinfo()
    db = pymysql.connect(**dbinfo)
    cursor = db.cursor()
    return db, cursor
Beispiel #6
0
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)