Exemple #1
0
def sort_response(json, field_name, other_field, reverse_order):
    if other_field:
        json.sort(key=lambda item: item['info'][field_name],
                  reverse=reverse_order)
    else:
        json.sort(key=lambda item: item[field_name], reverse=reverse_order)
    return json
def download_versioned_cdragon_champion_summary():
    json = utils.download_json(
        constants.cdragon_url +
        f"/{settings.patch['cdragon']}/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json"
    )
    json = list(filter(lambda x: (x['id'] != -1), json))
    # for x in json:
    #     if x['alias'] == "FiddleSticks":
    #         x['alias'] = "Fiddlesticks"
    json.sort(key=champion.get_alias)
    return json
def jsonToString(json, printing = True, decoding = 'unicode-escape', separator = ' ', lmbda = lambda k: 'zzz' if k in ['title', 'subTitle'] else k, sort = True, deep = 0):
    if type(json) == bytes:
        v = fixQuotes(json.decode('utf8'))
        return '\"' + v + '\"'
    if type(json) == str:
        return '\"' + fixQuotes(json) + '\"'
    text = ''
    if type(json) is dict:
        text = '{' + separator
        keys = list(json.keys())
        for k in keys:
            json[k] = jsonToString(json[k], False, decoding, ' ', sort = sort, deep = deep+1)
        keys.sort(key=lmbda)
        for k in keys:
            strK = '' 
            strV = '' 
            if type(json[k]) is str:
                #print('I am an unicode!', json[k]) 
                strV = json[k].encode('utf-8')
            else:
                strV = json[k] 
            if type(k) is bytes:
                strK = fixQuotes(k)
            elif type(k) is str:
                strK = k.encode('utf-8')
            else:
                strK = bytes(k)
            line = ('\"' +  strK.decode('utf-8') + '\": ' + strV.decode('utf-8') + ',' + separator)
            text += line
        text = (text[:-2] if len(json) > 0 else text) + separator + '}'
    elif type(json) is list:
        if deep == 0 or (deep > 0 and sort):
            json.sort()
        text = '[' + separator
        for v in json: 
            text += jsonToString(v, False, decoding, sort = sort, deep = deep+1) + ',' + separator
        text = (text[:-2] if len(json) > 0 else text) + separator + ']'
    elif json is None:
        text += 'null'
    elif type(json) is bool:
        text += 'true' if json else 'false'
    else:
        text += str(json)
    if printing: print_(text)
    return text
Exemple #4
0
def getRecentEvent(old_cfp):
    conferences = [
        ["ISCA",   "http://www.wikicfp.com/cfp/program?id=1683&s=ISCA&f=International%20Symposium%20on%20Computer%20Architecture"],
        ["ASPLOS", "http://www.wikicfp.com/cfp/program?id=242&s=ASPLOS&f=Architectural%20Support%20for%20Programming%20Languages%20and%20Operating%20Systems"],
        ["MICRO",  "http://www.wikicfp.com/cfp/program?id=2052&s=MICRO&f=International%20Symposium%20on%20Microarchitecture"],
        ["HPCA",   "http://www.wikicfp.com/cfp/program?id=1220&s=HPCA&f=High-Performance%20Computer%20Architecture"],
        ["CGO",    "http://www.wikicfp.com/cfp/program?id=429&s=CGO&f=Symposium%20on%20Code%20Generation%20and%20Optimization"],
        ["PLDI",   "http://www.wikicfp.com/cfp/program?id=2369&s=PLDI&f=Programming%20Language%20Design%20and%20Implementation"],
        ["LCTES",  "http://www.wikicfp.com/cfp/program?id=1950&s=LCTES&f=Languages,%20Compilers,%20and%20Tools%20for%20Embedded%20Systems"],
        ["PACT",   "http://www.wikicfp.com/cfp/program?id=2291&s=PACT&f=International%20Conference%20on%20Parallel%20Architectures%20and%20Compilation%20Techniques"],
        ["ISMM",   "http://www.wikicfp.com/cfp/program?id=1730&s=ISMM&f=International%20Symposium%20on%20Memory%20Management"],
        ]

    json = []
    for i, conf in enumerate(conferences):
        json.append(getWikiCfp(conf[1], old_cfp[i][0]))

    json.sort(compare)
    return json
Exemple #5
0
def get_transaction_history(chain):
    r = chain.get_history()
    json = r.json()
    data = []
    for i in json:
        x = dateutil.parser.parse(i['transactionTimestamp'])
        i['transactionTimestamp'] = x.strftime("%m-%d-%Y %H:%M:%S")

    json.sort(key=lambda item: item['transactionTimestamp'])  #, reverse=True)
    for i in json:
        str = "Transaction Time: %s\n" % i['transactionTimestamp']
        str += "Transaction Type: %s\n" % i['transactionType']
        str += "Transaction ID: %s\n" % i['transactionId']
        try:
            str += "Invoked By: %s\n" % i['participantInvoking']
        except:
            pass
        if i['eventsEmitted'] == []:
            str += "Events Emitted: None\n"
        else:
            str += "Events Emitted: \n"
            count = 1
            for x in i['eventsEmitted']:
                str += "\tEvent #%s\n" % count
                for key in x:
                    if key != "$class" and key != "eventID" and key != "timestamp":
                        capKey = key.capitalize()
                        str += "\t\t%s: %s\n" % (capKey, x[key])
                    elif key == "$class":
                        str += "\t\tType: %s\n" % x[key]
                    elif key == "eventID":
                        str += "\t\tID: %s\n" % x[key]
                    elif key == "timestamp":
                        dateKey = dateutil.parser.parse(x[key])
                        str += "\t\tTimestamp: %s\n" % dateKey.strftime(
                            "%m-%d-%Y %H:%M:%S")
        data.append(str)

    return data
Exemple #6
0
def validate_board(json):
    """ Converts and checks an board from a json object to an ordered array """
    if not type(json) == list:
        raise ValidationError("JSON should be an array")
    places_taken = {}
    for dam in json:
        if not type(dam) == list or len(dam) != 3:
            raise ValidationError("JSON array should only contain arrays of length 3")
        bw = dam[0]
        nq = dam[1]
        place = dam[2]
        if int(bw) < 0 or int(bw) > 1:
            raise ValidationError("JSON piece should only contain pieces that are black or white")
        if int(nq) < 0 or int(nq) > 1:
            raise ValidationError("JSON piece should only contain pieces that are normal or double")
        if int(place) < 1 or int(place) > 50:
            raise ValidationError("JSON piece should only contain pieces that are on the board (between 1 and 50)")
        if place in places_taken:
            raise ValidationError("JSON array should only contain one piece per place")
        places_taken[place] = True
    json.sort(key=lambda piece: piece[2])
    return json