예제 #1
0
파일: utils.py 프로젝트: kpelelis/onevone
 def populate_matchups(cls, limit=50, region='EUNE'):
     session = DBManager.create_session(expire_on_commit=False)
     matches = session.query(QueuedMatch).filter_by(region=region).filter(
         ~exists().where(QueuedMatch.id == CheckedMatch.id))\
         .limit(limit).all()
     for match in matches:
         payload = {
             'api_key': RIOT_API_KEY,
             'includeTimeline': 'true',
         }
         log.debug('Fetching info for match {0}'.format(match.id))
         url = 'https://{0}.api.pvp.net/api/lol/{0}'.format(region.lower())
         endpoint = '/{0}/match/{1}'.format(api_versions['match'], match.id)
         try:
             result = riot_api.get(url=url,
                                   endpoint=endpoint,
                                   payload=payload)
         except ForbiddenException:
             continue
         except NotFound:
             continue
         cls.populate_single_matchup(result)
         checked_match = CheckedMatch({
             'id':
             match.id,
             'region':
             match.region,
             'checked_at':
             datetime.now(),
             'match_timestamp':
             match.match_timestamp
         })
         session.merge(checked_match)
         session.commit()
예제 #2
0
from onevone import log

__all__ = [
    'ChampionAPI',
    'MasteryAPI',
    'RunesAPI',
    'ItemsAPI',
    'MatchupAPI',
    'SummonerSpellAPI',
    'Index',
    'About',
    'Contact',
    'MatchupView',
]

view_session = DBManager.create_session(expire_on_commit=False)


def create_error_response(message, error_code):
    data = json.dumps({'error': True, 'message': message})
    response = Response(status=error_code, mimetype='application/json')
    response.set_data(data)
    return response


def create_success_response(payload):
    data = json.dumps({
        'data': payload,
    })
    response = Response(status=200, mimetype='application/json')
    response.set_data(data)