Ejemplo n.º 1
0
def collection_update(jsonDict):
    PATH = 'Collection/My_Collection.json'
    if jsonDict['Action'] == 'Overwrite':
        myCollection = {}
    if jsonDict['Action'] == 'Update':
        myCollection = collection_open(PATH)

    for card in jsonDict['Complete']:
        name = card_info_handler.simple_guid_to_names(card['Guid']['m_Guid'])
        number = card['Count']
        myCollection[name] = number
    for card in jsonDict['CardsAdded']:
        name = card_info_handler.simple_guid_to_names(card['Guid']['m_Guid'])
        number = card['Count']
        if name in myCollection:
            myCollection[name] += number
        else:
            myCollection[name] = number


    for card in jsonDict['CardsRemoved']:
        try:
            name = card_info_handler.simple_guid_to_names(card['Guid']['m_Guid'])
            if name in myCollection:
                myCollection[name] -= number
        except Exception:
            if config_handler.getter('verboseFlag'):
                print("Tried to remove a card that was not in the collection (most likely")
                raise
    with collectionLock:
        with open(PATH, 'wt') as fp:
            json.dump(myCollection, fp, indent=4, sort_keys=True)
Ejemplo n.º 2
0
    def my_data_parsing(self, jsonDict):

        # Write data to log
        #if jsonDict['Message'] not in ('PlayerUpdated', 'CardUpdated') or self.verboseFlag:
        if config_handler.getter('API_logging'):
            with open(APIHandler.store_path, 'a') as fp:
                fp.write(datetime.datetime.now().strftime('%H:%M:%S') + '\t' + str(jsonDict) + '\n')

        myMessage = ('', '')
        # First DraftPack for the last 20 minutes
        if jsonDict['Message'] == 'DraftPack' and len(jsonDict['Cards']) == 17 and (time.time() - APIHandler.startTime) >= 1500:
            threading.Thread(target=self.play_sound, args=('Sounds/short_ringtone.wav',)).start()
            APIHandler.startTime = time.time()
            gui_queue.put(('Reset', 'Reset draft value'))

        if jsonDict['Message'] == 'GameStarted':
            threading.Thread(target=self.play_sound, args=('Sounds/game_start.wav',)).start()

        if jsonDict['Message'] == 'DraftPack':
            # jsonDict['Cards'] is a list of card-dictionaries.
            # Each card-dictionary has the Guid, Flags and Gems keys
            draftPack = [card_info_handler.simple_guid_to_names(x['Guid']['m_Guid']) for x in jsonDict['Cards']]
            myMessage = ('DraftPack', draftPack)
            gui_queue.put(myMessage)

        elif jsonDict['Message'] == 'DraftCardPicked':
            card_picked = card_info_handler.simple_guid_to_names(jsonDict['Card']['Guid']['m_Guid'])
            myMessage = ('CardPicked', card_picked )
            gui_queue.put(myMessage)

            #threading.Thread(target=collection_handler.update_draft_value, args =(ahData[jsonDict[2][0]],)).start()
            # Needs updating to new format
            # collection_handler.draft_card_picked('Collection/My_Drafted_Cards.json', jsonDict['Card'])

        elif jsonDict['Message'] == 'Collection':
            if not os.path.isfile('Collection/My_Collection.json') and jsonDict['Action'] == 'Overwrite':
                gui_queue.put(('Update', 'Collection updated'))
            with APIHandler.collectionLock:
                collection_handler.collection_update(jsonDict)