コード例 #1
0
def _get_membershipfile(club, membershipfile=None, membercachefilename=None, update=False, debug=False, raprivuser=None, key=None, secret=None):
#----------------------------------------------------------------------
    '''
    if membershipfile not supplied, retrieve from runningaheadmembers

    :param membershipfile: filename, file handle, or list with member data (optional)
    :param membercachefilename: name of optional file to cache detailed member data
    :param update: update member cache based on latest information from RA
    :param debug: True for debugging, default False
    :param raprivuser: hash for RA user with privileges for indicated club, if not supplied retrieved from apikeys
    :param key: ra key for oauth, if omitted retrieved from apikey
    :param secret: ra secret for oauth, if omitted retrieved from apikey
    :rtype: membershipfile
    '''

    if not membershipfile:
        if not raprivuser:
            ak = apikey.ApiKey('Lou King','running')
            try:
                raprivuser = ak.getkey('raprivuser')
            except apikey.unknownKey:
                raise parameterError("'raprivuser' key needs to be configured using apikey")

        membershipfile = ra2members(club, raprivuser, membercachefilename=membercachefilename, update=update, debug=debug, key=key, secret=secret, exp_date='ge.1990-01-01', ind_rec=1)

    return membershipfile
コード例 #2
0
ファイル: runningahead.py プロジェクト: wkolbenschlag/running
    def __init__(self,
                 membercachefilename=None,
                 debug=False,
                 key=None,
                 secret=None):
        #----------------------------------------------------------------------
        """
        initialize oauth authentication, and load member cache
        """

        # does user want to debug?
        if debug:
            # set up debug logging
            logging.basicConfig(
            )  # you need to initialize logging, otherwise you will not see anything from requests
            logging.getLogger().setLevel(logging.DEBUG)
            requests_log = logging.getLogger("requests.packages.urllib3")
            requests_log.setLevel(logging.DEBUG)
            requests_log.propagate = True
        else:
            pass  # how to stop?

        # get credentials from configuration if not provided
        if not (key and secret):
            ak = apikey.ApiKey('Lou King', 'running')
            try:
                key = ak.getkey('ra')
                secret = ak.getkey('rasecret')
            except apikey.unknownKey:
                raise parameterError, "'ra' and 'rasecret' keys needs to be configured using apikey"

        # Step 3 from http://api.runningahead.com/docs/authentication (using client_credentials, not authorization_code)
        # see http://requests-oauthlib.readthedocs.org/en/latest/oauth2_workflow.html#legacy-application-flow
        client = BackendApplicationClient(client_id=key)
        oauth = OAuth2Session(client=client)
        data = oauth.fetch_token(
            token_url='https://api.runningahead.com/oauth2/token',
            client_id=key,
            client_secret=secret)
        self.client_credentials = data['access_token']

        # set up session for multiple requests
        self.rasession = requests.Session()

        # bring in cache file, if requested
        self.membercache = {}
        self.membercachefilename = membercachefilename
        if self.membercachefilename:
            # only read cache if file exists
            if os.path.isfile(membercachefilename):
                with open(membercachefilename, 'r') as membercachefile:
                    # members are stored one per line, in json format
                    for line in membercachefile:
                        member = json.loads(line)
                        self.membercache[member['id']] = member
        # optimization - no write on close if not updated
        self.membercacheupdated = False
コード例 #3
0
ファイル: strava.py プロジェクト: wkolbenschlag/running
    def __init__(self, clubactivitycachefilename=None, debug=False, key=None):
        #----------------------------------------------------------------------
        """
        initialize 
        """

        # get credentials from configuration
        if not key:
            ak = apikey.ApiKey('Lou King', 'running')
            try:
                # key = ak.getkey('stravakey')
                # secret = ak.getkey('stravasecret')
                user = ak.getkey('stravauser')
            except apikey.unknownKey:
                raise parameterError, "'stravauser' needs to be configured using apikey"
        else:
            user = key

        self.user = user

        # set up debug logging, if desired
        if debug:
            logging.basicConfig(
            )  # you need to initialize logging, otherwise you will not see anything from requests
            logging.getLogger().setLevel(logging.DEBUG)
            requests_log = logging.getLogger("requests.packages.urllib3")
            requests_log.setLevel(logging.DEBUG)
            requests_log.propagate = True

        # bring in clubactivitycache file, if requested
        self.clubactivitycache = {}
        self.clubactivitycachefilename = clubactivitycachefilename
        if self.clubactivitycachefilename:
            # only read clubactivitycache if file exists
            if os.path.isfile(clubactivitycachefilename):
                with open(clubactivitycachefilename,
                          'r') as clubactivitycachefile:
                    # members are stored one per line, in json format
                    for line in clubactivitycachefile:
                        activity = json.loads(line)
                        id = activity['id']
                        # make sure there are no duplicates initially
                        if id not in self.clubactivitycache:
                            self.clubactivitycache[id] = activity

        # keep track of size of cache and number of activities added
        self.clubactivitycachesize = len(self.clubactivitycache)
        self.clubactivitycacheadded = 0
コード例 #4
0
    def __init__(self, key=None, debug=False):
        #----------------------------------------------------------------------
        """
        initialize http and get athlinks key
        """
        # get credentials from configuration
        self.key = key
        if not self.key:
            ak = apikey.ApiKey('Lou King', 'running')
            try:
                self.key = ak.getkey('athlinks')
            except apikey.unknownKey:
                raise parameterError, "'athlinks' key needs to be configured using apikey"

        # need http object
        self.http = httplib2.Http(timeout=HTTPTIMEOUT)

        # set up logging level
        self.log = logging.getLogger('running.athlinks')
        self.setdebug(debug)

        # count how many pages have been retrieved
        self.urlcount = 0
コード例 #5
0
# pypi
import pytz  # also consider https://pypi.python.org/pypi/gaepytz (tuned for google app engine)
import httplib2

# github
import gpxpy
import gpxpy.geo

# home grown
import version
from running import *
from loutilities import timeu
from loutilities import apikey

_ak = apikey.ApiKey('Lou King', 'running')
try:
    _FORECASTIOKEY = _ak.getkey('forecastio')
except apikey.unknownKey:
    print "'forecastio' key needs to be configured using apikey"
    raise

WXPERIOD = 5 * 60  # number of seconds between weather assessments
#tgpx = timeu.asctime('%Y-%m-%dT%H:%M:%S%Z')

HTTPTIMEOUT = 5
HTTPTZ = httplib2.Http(timeout=HTTPTIMEOUT)
HTTPWX = httplib2.Http(timeout=HTTPTIMEOUT,
                       disable_ssl_certificate_validation=True)

# dewpoint from http://www.meteo-blog.net/2012-05/dewpoint-calculation-script-in-python/