Esempio n. 1
0
 def saveLocal(self):
     try:
         with open(constants.getCacheFilePath('localMatches.json'),
                   'w+',
                   encoding='utf-8') as fp:
             json.dump(self.localMatches, fp, ensure_ascii=False, indent=2)
     except Exception as e:
         print('save cache error: ', e)
Esempio n. 2
0
 def save(self):
     try:
         with open(constants.getCacheFilePath('matchDetails.json'),
                   'w+',
                   encoding='utf-8') as fp:
             json.dump(self.matchDetails, fp, ensure_ascii=False, indent=2)
         with open(constants.getCacheFilePath('riotIds.json'),
                   'w+',
                   encoding='utf-8') as fp:
             json.dump(self.riotIds, fp, ensure_ascii=False, indent=2)
         with open(constants.getCacheFilePath('playerNames.json'),
                   'w+',
                   encoding='utf-8') as fp:
             json.dump(self.playerNames, fp, ensure_ascii=False, indent=2)
         with open(constants.getCacheFilePath('matches.json'),
                   'w+',
                   encoding='utf-8') as fp:
             json.dump(self.matches, fp, ensure_ascii=False, indent=2)
     except Exception as e:
         print('save cache error: ', e)
Esempio n. 3
0
def get_playernames(server):
    url = f"https://raw.githubusercontent.com/LoR-Master-Tracker/LoR-Player-Crawler/master/save/{server}.json"
    print('Loading: ', url)
    r = session.get(url)

    # valid json:
    try:
        jsonObject = r.json()
    except Exception as e:
        print(url, 'Json valid issue: ', e)
        return
    with open(constants.getCacheFilePath(server.lower() + '.json'),
              'w',
              encoding='utf-8') as fp:
        json.dump(jsonObject, fp, ensure_ascii=False, indent=2)
Esempio n. 4
0
 def loadJson(self):
     try:
         with open(constants.getCacheFilePath('matchDetails.json'),
                   'r',
                   encoding='utf-8') as fp:
             self.matchDetails = json.load(fp)
     except Exception as e:
         print('loadJson matchDetails error', e)
     try:
         with open(constants.getCacheFilePath('riotIds.json'),
                   'r',
                   encoding='utf-8') as fp:
             self.riotIds = json.load(fp)
     except Exception as e:
         print('loadJson riotIds error', e)
     try:
         with open(constants.getCacheFilePath('playerNames.json'),
                   'r',
                   encoding='utf-8') as fp:
             self.playerNames = json.load(fp)
     except Exception as e:
         print('loadJson playerNames error', e)
     try:
         with open(constants.getCacheFilePath('matches.json'),
                   'r',
                   encoding='utf-8') as fp:
             self.matches = json.load(fp)
     except Exception as e:
         print('loadJson matches error', e)
     try:
         with open(constants.getCacheFilePath('localMatches.json'),
                   'r',
                   encoding='utf-8') as fp:
             self.localMatches = json.load(fp)
     except Exception as e:
         print('loadJson localMatches error', e)
Esempio n. 5
0
def get_names(server, playername):
    # to-do move functions to master model
    playernames = set()
    nameListPath = constants.getCacheFilePath(server.lower() + '.json')
    if not os.path.isfile(nameListPath):
        nameListPath = 'Resource/' + server.lower() + '.json'
    try:
        with open(nameListPath, 'r', encoding='utf-8') as fp:
            names = json.load(fp)
            for name in names.items():
                playernames.add(name[0] + '#' + name[1])
    except Exception as e:
        print('updatePlayernames', e)
    playerList = set()
    for name in playernames:
        if name[0:len(playername)].lower() == playername.lower():
            playerList.add(name)
    returnList = jsonify(list(playerList))
    return returnList