Example #1
0
def getStaticData():
    url = "https://datafeeds.networkrail.co.uk/ntrod/CifFileAuthenticate?type=CIF_HU_TOC_FULL_DAILY&day=toc-full"
    # set auth tokens
    # This is a daily file, check it doesn't exist.
    # TODO fix the daily thing - just skips atm
    # TODO - can remove all checks. will download daily via cron....
    for f in os.listdir(extractdir):
        if fnmatch.fnmatch(f, 'CIF*.gz'):
            ftime = os.path.getmtime(extractdir + f)
            ftime = datetime.datetime.fromtimestamp(ftime)
            ctime = datetime.datetime.fromtimestamp(time.time())
            if ftime.year >= ctime.year:
                # print(ftime.year)
                # print(ctime.year)
                if ftime.month >= ctime.month:
                    # print(ftime.month)
                    # print(ctime.month)
                    if ftime.day >= ftime.day:
                        # print(ftime.month)
                        # print(ctime.month)
                        print('Already have current file. Skipping...')
            else:
                print("Don't have current file. Downloading...")
                r = requests.get(url, auth=HTTPBasicAuth(token.getToken('railuser'), token.getToken('railpass')))
                print(r.url)
Example #2
0
    def onXfwCommand(self, cmd, *args):
        try:
            if IS_DEVELOPMENT and cmd in _LOG_COMMANDS:
                debug("cmd=" + str(cmd) + " args=" + simplejson.dumps(args))

            if cmd == XVM_COMMAND.REQUEST_CONFIG:
                self.respondConfig()
                return (None, True)

            if cmd == XVM_COMMAND.GET_BATTLE_LEVEL:
                arena = getattr(BigWorld.player(), 'arena', None)
                if arena is not None:
                    return (arena.extraData.get('battleLevel', 0), True)
                return (None, True)

            if cmd == XVM_COMMAND.GET_BATTLE_TYPE:
                arena = getattr(BigWorld.player(), 'arena', None)
                if arena is not None:
                    return (arena.bonusType, True)
                return (None, True)

            if cmd == XVM_COMMAND.REQUEST_DOSSIER:
                dossier.requestDossier(args)
                return (None, True)

            if cmd == XVM_COMMAND.GET_SVC_SETTINGS:
                token.getToken()
                return (token.networkServicesSettings, True)

            if cmd == XVM_COMMAND.LOAD_SETTINGS:
                default = None if len(args) < 2 else args[1]
                return (userprefs.get(args[0], default), True)

            if cmd == XVM_COMMAND.LOAD_STAT_BATTLE:
                stats.getBattleStat(args)
                return (None, True)

            if cmd == XVM_COMMAND.LOAD_STAT_BATTLE_RESULTS:
                stats.getBattleResultsStat(args)
                return (None, True)

            if cmd == XVM_COMMAND.LOAD_STAT_USER:
                stats.getUserData(args)
                return (None, True)

            if cmd == XVM_COMMAND.OPEN_URL:
                if len(args[0]):
                    utils.openWebBrowser(args[0], False)
                return (None, True)

            if cmd == XVM_COMMAND.SAVE_SETTINGS:
                userprefs.set(args[0], args[1])
                return (None, True)

        except Exception, ex:
            err(traceback.format_exc())
            return (None, True)
Example #3
0
def auth():  #createKey(refId):
    user = createUser()
    if (user != 0):
        key = createKey(user)
        if (key != 0):
            encodeStr = f'{user}:{key}'
            result = encode(encodeStr)
            token = getToken(result)
            print(
                '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ access token :'
            )
            print(token)
            return token
Example #4
0
def pic2word(pic_location):
    # getToken key
    key = dict()
    keyFile = open('../res/keys.properties', 'r')
    for line in keyFile:
        key.update({line.split('=')[0]: line.split('=')[1]})
    keyFile.close()
    access_token = getToken(key["APIKey"].strip('\n'),
                            key["SecretKey"].strip('\n'))
    url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=' + json.loads(
        access_token)['access_token']
    # 二进制方式打开图文件
    f = open(pic_location, 'rb')
    # 参数image:图像base64编码
    img = base64.b64encode(f.read())
    params = {"image": img}
    params = urllib.urlencode(params)
    request = urllib2.Request(url, params)
    request.add_header('Content-Type', 'application/x-www-form-urlencoded')
    response = urllib2.urlopen(request)
    content = response.read()
    if (content):
        return content
    return
Example #5
0
uname = '*****@*****.**'
passwd = 'd3a907fbea42783d'

if base is None:
    try:    ind = __file__.rindex('/' if '/' in __file__ else '\\')
    except: ind = len(__file__)
    base = __file__[:ind+1] #Get absolute path of base dir

base_dir = base + '/UserData/'
sleep_span = 0.1
REQUEST_MAX_TRY = 3

if debug_enable and access_token is None:
    from token import getToken
    access_token = getToken(uname,passwd)
    print(access_token)

schema='https' if debug_enable else 'http'
domain = 'api.weibo.com' if debug_enable else 'i2.api.weibo.com'
client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL,schema=schema,domain=domain)
client.access_token = access_token

def get_user_profile(**kwargs):
    val = key = None
    try:
        val = kwargs.pop('screen_name')
        key = 'screen_name'
    except:
        pass
Example #6
0
passwd = 'd3a907fbea42783d'

if base is None:
    try:
        ind = __file__.rindex('/' if '/' in __file__ else '\\')
    except:
        ind = len(__file__)
    base = __file__[:ind + 1]  #Get absolute path of base dir

base_dir = base + '/UserData/'
sleep_span = 0.1
REQUEST_MAX_TRY = 3

if debug_enable and access_token is None:
    from token import getToken
    access_token = getToken(uname, passwd)
    print(access_token)

schema = 'https' if debug_enable else 'http'
domain = 'api.weibo.com' if debug_enable else 'i2.api.weibo.com'
client = APIClient(app_key=APP_KEY,
                   app_secret=APP_SECRET,
                   redirect_uri=CALLBACK_URL,
                   schema=schema,
                   domain=domain)
client.access_token = access_token


def get_user_profile(**kwargs):
    val = key = None
    try: