Example #1
0
 def add(self, serie, season, ep, force=False):
     serie = fix_name(serie)
     if not self.__collection.add(serie, int(season), int(ep), force=force):
         print(self.__collection.lasterror)
         return False
     self.__collection.save()
     return True
Example #2
0
async def clean_collection_tiers(data, contributors):
    if not data: return

    # {category: {collection: value, ...}, ...}
    collection_categories = {}

    for minion_name_raw in data:
        # collections are formatted as COLLECTION_LEVEL
        collection_name, collection_level = minion_name_raw.rsplit('_', 1)
        collection_level = int(collection_level)
        collection_category = choose_collection_category(collection_name)
        collection_name = utils.fix_name(collection_name, 'collection')

        # If it's not upgraded it'll be -1, so fix it to be 0
        if collection_level == -1:
            collection_level = 0

        if collection_category not in collection_categories:
            collection_categories[collection_category] = {}
        current_collection_level = collection_categories[
            collection_category].get(collection_name, {}).get('level', -1)
        if collection_level > current_collection_level:
            collection_data = {'level': collection_level, 'contributors': {}}
            if collection_name in contributors:
                collection_contributors = contributors[collection_name]
                for member_uuid in collection_contributors:
                    contributed = collection_contributors[member_uuid]
                    collection_data['contributors'][member_uuid] = contributed
            collection_categories[collection_category][
                collection_name] = collection_data
    return collection_categories
Example #3
0
def choose_collection_category(raw_collection_name):
    for category_name in collection_categories:
        if utils.fix_name(
                raw_collection_name,
                'collection') in collection_categories[category_name]:
            return category_name
    return 'other'
Example #4
0
 def delete(self, serie):
     serie = fix_name(serie)
     if not self.__collection.delete(serie):
         print(self.__collection.lasterror)
         return False
     self.__collection.save()
     return True
Example #5
0
 def delete(self, serie):
     serie = fix_name(serie)
     if not self.__collection.delete(serie):
         print(self.__collection.lasterror)
         return False
     self.__collection.save()
     return True
Example #6
0
 def add(self, serie, season, ep, force=False):
     serie = fix_name(serie)
     if not self.__collection.add(serie, int(season), int(ep), force=force):
         print(self.__collection.lasterror)
         return False
     self.__collection.save()
     return True
def write_file(file):       # This method write the final file in .hack extention
    newFileName = utils.fix_name(filename, op=".")
    newFileName = newFileName+".hack"
    newfile = open(newFileName,'w')

    for lines in file:
        newfile.write(lines+"\n")
    newfile.close()
Example #8
0
async def get_average_prices():
    r = await request('products/averages')
    output = {}
    for product in r:
        average = r[product]
        product_name = utils.fix_name(product, 'bazaar')
        output[product_name] = round(average, 2)
    return output
Example #9
0
    def _enqueue_output(self):
        song = random.choice(self.songs)
        self.log("get song id" + song['id'])
        retry = 3
        while retry > 0:
            try:
                filename, audio = self.mm.download_song(song['id'])
                if len(audio) == 0:
                    self.log("audio size 0")
                    song = random.choice(self.songs)
                    continue

                filelike = StringIO.StringIO(audio)
                metadata = mutagen.File(filelike)
                output = {
                    'song_length': 0,
                    'album': '',
                    'artist': '',
                    'title': '',
                    'audio': audio
                }

                if metadata:
                    output['song_length'] = metadata.info.length
                    output['album'] = fix_name(
                        (metadata.tags or metadata).get('TALB', dummy).text[0])
                    output['artist'] = fix_name(
                        (metadata.tags or metadata).get('TPE1', dummy).text[0])
                    output['title'] = fix_name(
                        (metadata.tags or metadata).get('TIT2', dummy).text[0])

                self.queue.put(output)
                break
            except CallFailure:
                self.log("call failure")
                song = random.choice(self.songs)
                retry -= 1

        if retry == 0:
            self.log("Google Music download fail, please restart the program")
            self.queue.put({})
Example #10
0
 def parse(self):
     (void, ext) = os.path.splitext(os.path.basename(self._path))
     self._ext = ext.lstrip(".")
     for _re in self.RE:
         match = re.match(_re, os.path.basename(self._path))
         if match:
             md = match.groupdict()
             self._serie = fix_name(md["serie"])
             self._episode = Episode(int(md["season"]), int(md["ep"]))
             break
     else:
         raise UnknownFile(self._path)
Example #11
0
async def get_current_prices():
    r = await request('products/current')
    output = []
    for product in r:
        product_name = utils.fix_name(product['productId'], 'bazaar')
        output.append({
            'id': product_name,
            'buy_price': product['buyPrice'],
            'sell_price': product['sellPrice'],
            'buy_volume': product['buyVolume'],
            'sell_volume': product['sellVolume'],
            'average': round(product['average'], 2),
        })
    return output
Example #12
0
 def show(self, serie_filter=None):
     serie_filter = fix_name(serie_filter) if serie_filter else None
     series = self.__get_filtered(serie_filter)
     if not series:
         return
     longest_len = len(sorted(series.keys(), key=len)[-1])
     now = datetime.date.today()
     for serie in sorted(series.values(), key=attrgetter("name")):
         line = []
         line.append("%*s %s" % (longest_len, serie.name, serie.current))
         line.append("%-24s" % colored(serie.desc["message"], serie.desc["color"]))
         line.append("%s" % colored((abs(serie.desc["days"]) * ("+" if serie.desc["days"] >= 0 else "-")), serie.desc["color"]))
         print(" | ".join(line))
     print("%i serie%s" % (len(series), "s" if len(series) > 1 else ""))
Example #13
0
async def clean_profile(data):
    profile_raw = data.get('profile')
    if not profile_raw: return {}
    profile_id = profile_raw['profile_id']
    members_list = []
    all_minions = set()

    collection_tiers = None
    collection_contributors = {}

    for member_uuid in profile_raw['members']:
        member_data_raw = profile_raw['members'][member_uuid]
        member_data = clean_profile_member(member_data_raw, member_uuid)
        members_list.append(member_data)
        if 'crafted_generators' in member_data_raw:
            all_minions.update(member_data_raw['crafted_generators'])
        if 'unlocked_coll_tiers' in member_data_raw:
            collection_tiers = member_data_raw['unlocked_coll_tiers']
        if 'collection' in member_data_raw:
            for raw_collection in member_data_raw['collection']:
                collection_name = utils.fix_name(raw_collection, 'collection')
                if collection_name not in collection_contributors:
                    collection_contributors[collection_name] = {}
                collection_xp = member_data_raw['collection'][raw_collection]
                collection_contributors[collection_name][
                    member_uuid] = collection_xp
    bank = profile_raw.get('banking', {}).get('balance')
    bank_history = profile_raw.get('banking', {}).get('transactions')

    output = {
        'uuid':
        profile_id,
        'members':
        members_list,
        'bank':
        bank,
        'bank_history':
        clean_bank_history(bank_history),
        'crafted_minions':
        clean_minions(all_minions),
        'minion_count':
        len(all_minions),
        'collections':
        await clean_collection_tiers(collection_tiers,
                                     collection_contributors),
    }
    return output
Example #14
0
 def show(self, serie_filter=None):
     serie_filter = fix_name(serie_filter) if serie_filter else None
     series = self.__get_filtered(serie_filter)
     if not series:
         return
     longest_len = len(sorted(series.keys(), key=len)[-1])
     now = datetime.date.today()
     for serie in sorted(series.values(), key=attrgetter("name")):
         line = []
         line.append("%*s %s" % (longest_len, serie.name, serie.current))
         line.append("%-24s" %
                     colored(serie.desc["message"], serie.desc["color"]))
         line.append("%s" % colored(
             (abs(serie.desc["days"]) *
              ("+" if serie.desc["days"] >= 0 else "-")),
             serie.desc["color"]))
         print(" | ".join(line))
     print("%i serie%s" % (len(series), "s" if len(series) > 1 else ""))
Example #15
0
 def update(self, serie_filter=None):
     serie_filter = fix_name(serie_filter) if serie_filter else None
     series = self.__get_filtered(serie_filter)
     for serie_name in series:
         show = TvrageShow(serie_name)
         show.retr_show()
         if not self.__collection.set_showid(serie_name, show.showid):
             print(self.__collection.lasterror)
             return False
         if not self.__collection.set_ended(serie_name, show.ended):
             print(self.__collection.lasterror)
             return False
         show.retr_episodes()
         if not self.__collection.set_episodes(serie_name, show.lastep, show.nextep):
             print(self.__collection.lasterror)
             return False
     self.__collection.save()
     return True
Example #16
0
 def update(self, serie_filter=None):
     serie_filter = fix_name(serie_filter) if serie_filter else None
     series = self.__get_filtered(serie_filter)
     for serie_name in series:
         show = TvrageShow(serie_name)
         show.retr_show()
         if not self.__collection.set_showid(serie_name, show.showid):
             print(self.__collection.lasterror)
             return False
         if not self.__collection.set_ended(serie_name, show.ended):
             print(self.__collection.lasterror)
             return False
         show.retr_episodes()
         if not self.__collection.set_episodes(serie_name, show.lastep,
                                               show.nextep):
             print(self.__collection.lasterror)
             return False
     self.__collection.save()
     return True
Example #17
0
async def get_products():
    products = []
    for product in await request('products'):
        products.append(utils.fix_name(product, 'bazaar'))
    return products