示例#1
0
 def __init__(self, platform='KR', routing='ASIA'):
     self.api = TftWatcher(api_key=secret.RIOT_API_KEY)
     self.platform = platform
     self.routing = routing
     self.default_start_datetime = datetime.strptime(
         '2018-01-01 00:00:00', '%Y-%m-%d %H:%M:%S')
     self.default_start_timestamp = int(
         datetime.timestamp(self.default_start_datetime) * 1000)
     self.season5_start_datetime = datetime.strptime(
         '2021-04-28 12:00:00', '%Y-%m-%d %H:%M:%S')
     self.season5_start_timestamp = int(
         datetime.timestamp(self.season5_start_datetime) * 1000)
     self.db = DatabaseManager()
示例#2
0
from flask import Flask, request, jsonify
from flask_restx import Resource, Api
from riotwatcher import TftWatcher, ApiError
from settings import riot_key
from flask_cors import CORS

application = Flask(__name__)
api = Api(application)
cors = CORS(application, resources={r"*": {"origins": "*"}})
application.config['CORS_HEADERS'] = 'Content-Type'

api_key = riot_key
tft = TftWatcher(api_key)

regions = {
    'na1': 'americas',
    'br1': 'americas',
    'oc1': 'americas',
    'la1': 'americas',
    'la2': 'americas',
    'jp1': 'asia',
    'kr': 'asia',
    'eun1': 'europe',
    'euw1': 'europe',
    'tr1': 'europe',
    'ru': 'europe'
}

server, region = 'na1', 'americas'

from riotwatcher import LolWatcher, ApiError, TftWatcher
from utils.utils import print_if_complete
import pandas as pd
import json
import collections
from flatten_dict import flatten

# Global variables
api_key = 'RGAPI-767133c2-cd2b-434d-8c0f-0ce87e4cda40'
watcher = TftWatcher(api_key)
my_region = 'kr'
file = open("MyFile.txt", "a")


@print_if_complete
def league_puuid_lst(league):
    # Get user puuid list in certain league
    puuid_lst = list()
    for summoner_info in league['entries']:
        summonerId = summoner_info['summonerId']
        puuid = watcher.summoner.by_id(my_region, summonerId)['puuid']
        puuid_lst.append(puuid)
    return puuid_lst


@print_if_complete
def unique_match_id_lst(puuid_lst, count=10):
    # Get unqiue match id lst from a given list of user puuid
    res_lst = list()
    for puuid in puuid_lst:
        match_id_lst = watcher.match.by_puuid('asia', puuid, count=10)
 def test_require_api_key(self):
     with pytest.raises(ValueError):
         TftWatcher()
 def test_allows_keyword_api_key(self):
     TftWatcher(api_key="RGAPI-this-is-a-fake")
 def test_allows_positional_api_key(self):
     TftWatcher("RGAPI-this-is-a-fake")
示例#7
0
    for idx, match_id in enumerate(list_match_ids):
        try:
            response = tft_watcher.match.by_id(region_match, match_id)
            if (response['info']['game_datetime'] < limit_start_timestamp):
                break
            local_matches.append(response)
        except ApiError as err:
            print(err)
        print('Get matches by match ids... (%5d/%5d)' %
              (idx, len(list_match_ids)))
    return local_matches


if __name__ == '__main__':
    RIOT_API_KEY = secret.RIOT_API_KEY
    tft_watcher = TftWatcher(api_key=RIOT_API_KEY)
    region = 'KR'
    region_match = 'ASIA'

    season5_date_string = '2021-04-28 20:00:00'
    season5_start_date = datetime.strptime(season5_date_string,
                                           '%Y-%m-%d %H:%M:%S')
    season5_start_timestamp = int(
        datetime.timestamp(season5_start_date) * 1000)

    match_ids = None
    with open('data/match_ids.txt', 'rb') as in_file:
        match_ids = pickle.load(in_file)

    matches = GetMatchesByList(match_ids, season5_start_timestamp)
示例#8
0
config.read('config.ini')

key = configparser.ConfigParser()
key.read('keys.ini')

#connect to postgres database
connection = psycopg2.connect(
    host = key.get('database', 'host'),
    port = 5432,
    user = key.get('database', 'user'),
    password = key.get('database', 'password'),
    database = key.get('database', 'database')
    )

#get tft watcher
tft_watcher=TftWatcher(api_key=key.get('setup', 'api_key'))

#get all challenger summoner IDs and Summoner names
def getchallengerladder(region):
    testwatch=tft_watcher.league.challenger(region=region)
    ladder=pd.DataFrame(pd.json_normalize(testwatch['entries'])[['summonerId','summonerName']])
    ladder['region']=region
    return ladder

#Create db if does not yet exist
def createdbifnotexists():
    cursor=connection.cursor()
    cursor.execute("""CREATE TABLE IF NOT EXISTS LadderPuuid(
    id SERIAL PRIMARY KEY,
    summonerName text,
    summonerId text,