示例#1
0
def buildMangaReply(searchText, isExpanded, baseComment, blockTracking=False):
    try:
        ani = {
            'search_function': Anilist.getMangaDetails,
            'synonym_function': Anilist.getSynonyms,
            'checked_synonyms': [],
            'result': None
        }
        mal = {
            'search_function': MAL.getMangaDetails,
            'synonym_function': MAL.getSynonyms,
            'checked_synonyms': [],
            'result': None
        }
        kit = {
            'search_function': Kitsu.search_manga,
            'synonym_function': Kitsu.get_synonyms,
            'checked_synonyms': [],
            'result': None
        }
        mu = {'search_function': MU.getMangaURL, 'result': None}
        ap = {'search_function': AniP.getMangaURL, 'result': None}

        try:
            sqlCur.execute(
                'SELECT dbLinks FROM synonyms WHERE type = "Manga" and lower(name) = ?',
                [searchText.lower()])
        except sqlite3.Error as e:
            print(e)

        alternateLinks = sqlCur.fetchone()

        if (alternateLinks):
            synonym = json.loads(alternateLinks[0])

            if synonym:
                malsyn = None
                if 'mal' in synonym and synonym['mal']:
                    malsyn = synonym['mal']

                anisyn = None
                if 'ani' in synonym and synonym['ani']:
                    anisyn = synonym['ani']

                kitsyn = None
                if 'kit' in synonym and synonym['kit']:
                    kitsyn = synonym['kit']

                musyn = None
                if 'mu' in synonym and synonym['mu']:
                    musyn = synonym['mu']

                apsyn = None
                if 'ap' in synonym and synonym['ap']:
                    apsyn = synonym['ap']

                mal['result'] = MAL.getMangaDetails(
                    malsyn[0], malsyn[1]) if malsyn else None
                ani['result'] = Anilist.getMangaDetailsById(
                    anisyn) if anisyn else None
                kit['result'] = Kitsu.get_manga(kitsyn) if kitsyn else None
                mu['result'] = MU.getMangaURLById(musyn) if musyn else None
                ap['result'] = AniP.getMangaURLById(apsyn) if apsyn else None

        else:
            data_sources = [ani, kit, mal]
            aux_sources = [mu, ap]

            synonyms = set([searchText])

            for x in range(len(data_sources)):
                for source in data_sources:
                    if source['result']:
                        break
                    else:
                        for synonym in synonyms:
                            if synonym in source['checked_synonyms']:
                                continue

                            source['result'] = source['search_function'](
                                synonym)
                            source['checked_synonyms'].append(synonym)

                            if source['result']:
                                break

                    if source['result']:
                        synonyms.update([
                            synonym.lower() for synonym in
                            source['synonym_function'](source['result'])
                        ])

            for source in aux_sources:
                for synonym in synonyms:
                    source['result'] = source['search_function'](synonym)

                    if source['result']:
                        break

        if ani['result'] or mal['result'] or kit['result']:
            try:
                titleToAdd = ''
                if ani['result']:
                    try:
                        titleToAdd = ani['result']['title_romaji']
                    except:
                        titleToAdd = ani['result']['title_english']
                elif mal['result']:
                    titleToAdd = mal['result']['title']
                elif kit['result']:
                    try:
                        titleToAdd = kit['result']['title_romaji']
                    except:
                        titleToAdd = kit['result']['title_english']

                if (str(baseComment.subreddit).lower is not 'nihilate') and (
                        str(baseComment.subreddit).lower
                        is not 'roboragi') and not blockTracking:
                    DatabaseHandler.addRequest(titleToAdd, 'Manga',
                                               baseComment.author.name,
                                               baseComment.subreddit)
            except:
                traceback.print_exc()
                pass

        return CommentBuilder.buildMangaComment(isExpanded, mal['result'],
                                                ani['result'], mu['result'],
                                                ap['result'], kit['result'])

    except Exception as e:
        traceback.print_exc()
        return None
示例#2
0
def buildMangaReply(searchText, isExpanded, baseComment, blockTracking=False):
    """ Builds a manga reply from multiple sources """
    try:
        ani = {
            'search_function': Anilist.getMangaDetails,
            'title_function': Anilist.getTitles,
            'synonym_function': Anilist.getSynonyms,
            'checked_synonyms': [],
            'result': None
        }
        kit = {
            'search_function': Kitsu.search_manga,
            'synonym_function': Kitsu.get_synonyms,
            'title_function': Kitsu.get_titles,
            'checked_synonyms': [],
            'result': None
        }
        mu = {'search_function': MU.getMangaURL, 'result': None}
        ap = {'search_function': AniP.getMangaURL, 'result': None}

        try:
            query = ('SELECT dbLinks'
                     '  FROM synonyms'
                     ' WHERE type = "Manga"'
                     '   AND lower(name) = ?')
            sqlCur.execute(query, [searchText.lower()])
        except sqlite3.Error as e:
            print(e)

        alternateLinks = sqlCur.fetchone()

        if (alternateLinks):
            synonym = json.loads(alternateLinks[0])

            if synonym:
                anisyn = None
                if 'ani' in synonym and synonym['ani']:
                    anisyn = synonym['ani']

                kitsyn = None
                if 'kit' in synonym and synonym['kit']:
                    kitsyn = synonym['kit']

                musyn = None
                if 'mu' in synonym and synonym['mu']:
                    musyn = synonym['mu']

                apsyn = None
                if 'ap' in synonym and synonym['ap']:
                    apsyn = synonym['ap']

                if anisyn:
                    ani['result'] = Anilist.getMangaDetailsById(anisyn)
                else:
                    ani['result'] = None
                kit['result'] = Kitsu.get_manga(kitsyn) if kitsyn else None
                mu['result'] = MU.getMangaURLById(musyn) if musyn else None
                ap['result'] = AniP.getMangaURLById(apsyn) if apsyn else None

        else:
            data_sources = [ani, kit]
            aux_sources = [mu, ap]

            synonyms = set([searchText])
            titles = set()

            for x in range(len(data_sources)):
                for source in data_sources:
                    if source['result']:
                        break
                    else:
                        for title in titles:
                            if title in source['checked_synonyms']:
                                break

                            if source['result']:
                                break

                            source['result'] = source['search_function'](title)
                            source['checked_synonyms'].append(title)

                            if source['result']:
                                break

                        for synonym in synonyms:
                            if synonym in source['checked_synonyms']:
                                break

                            if source['result']:
                                break

                            search_function = source['search_function']
                            source['result'] = search_function(synonym)
                            source['checked_synonyms'].append(synonym)

                            if source['result']:
                                break

                    if source['result']:
                        result = source['result']
                        synonym_function = source['synonym_function']
                        title_function = source['title_function']
                        synonyms.update(
                            [s.lower() for s in synonym_function(result)])
                        titles.update(
                            [t.lower() for t in title_function(result)])

            for source in aux_sources:
                for title in titles:
                    source['result'] = source['search_function'](synonym)

                    if source['result']:
                        break

                if not source['result']:
                    for synonym in synonyms:
                        source['result'] = source['search_function'](synonym)

                        if source['result']:
                            break

        if ani['result'] or kit['result']:
            try:
                titleToAdd = ''
                if ani['result']:
                    try:
                        titleToAdd = ani['result']['title_romaji']
                    except Exception:
                        titleToAdd = ani['result']['title_english']
                elif kit['result']:
                    try:
                        titleToAdd = kit['result']['title_romaji']
                    except Exception:
                        titleToAdd = kit['result']['title_english']

                subreddit = str(baseComment.subreddit).lower
                ignored_subreddits = ('nihilate', 'roboragi')
                if subreddit not in ignored_subreddits and not blockTracking:
                    DatabaseHandler.addRequest(
                        name=titleToAdd,
                        rType='Manga',
                        requester=baseComment.author.name,
                        subreddit=baseComment.subreddit)
            except Exception:
                traceback.print_exc()
                pass

        if ani['result'] or kit['result']:
            return CommentBuilder.buildMangaComment(isExpanded=isExpanded,
                                                    ani=ani['result'],
                                                    mu=mu['result'],
                                                    ap=ap['result'],
                                                    kit=kit['result'])
        else:
            print('No result found for ' + searchText)
            return None

    except Exception:
        traceback.print_exc()
        return None
示例#3
0
def buildMangaReply(searchText, isExpanded, baseComment, blockTracking=False):
    try:
        ani = None
        mal = None
        mu = None
        ap = None

        try:
            sqlCur.execute(
                'SELECT dbLinks FROM synonyms WHERE type = "Manga" and lower(name) = ?',
                [searchText.lower()])
        except sqlite3.Error as e:
            print(e)

        alternateLinks = sqlCur.fetchone()

        if (alternateLinks):
            synonym = json.loads(alternateLinks[0])

            if (synonym['mal']):
                mal = MAL.getMangaDetails(synonym['mal'][0], synonym['mal'][1])
            if (synonym['ani']):
                ani = Anilist.getMangaDetailsById(synonym['ani'])
            if (synonym['mu']):
                mu = MU.getMangaURLById(synonym['mu'])
            if (synonym['ap']):
                ap = AniP.getMangaURLById(synonym['ap'])

        else:
            #Basic breakdown:
            #If Anilist finds something, use it to find the MAL version.
            #If hits either MAL or Ani, use it to find the MU version.
            #If it hits either, add it to the request-tracking DB.
            ani = Anilist.getMangaDetails(searchText)

            if ani:
                try:
                    mal = MAL.getMangaDetails(ani['title_romaji'])
                except:
                    pass

                if not mal:
                    try:
                        mal = MAL.getMangaDetails(ani['title_english'])
                    except:
                        pass

                if not mal:
                    mal = MAL.getMangaDetails(searchText)

            else:
                mal = MAL.getMangaDetails(searchText)

                if mal:
                    ani = Anilist.getMangaDetails(mal['title'])

        #----- Finally... -----#
        if ani or mal:
            try:
                titleToAdd = ''
                if mal:
                    titleToAdd = mal['title']
                else:
                    try:
                        titleToAdd = ani['title_english']
                    except:
                        titleToAdd = ani['title_romaji']

                if not alternateLinks:
                    #MU stuff
                    if mal:
                        mu = MU.getMangaURL(mal['title'])
                    else:
                        mu = MU.getMangaURL(ani['title_romaji'])

                    #Do the anime-planet stuff
                    if mal and not ap:
                        if mal['title'] and not ap:
                            ap = AniP.getMangaURL(mal['title'])
                        if mal['english'] and not ap:
                            ap = AniP.getMangaURL(mal['english'])
                        if mal['synonyms'] and not ap:
                            for synonym in mal['synonyms']:
                                if ap:
                                    break
                                ap = AniP.getMangaURL(synonym)

                    if ani and not ap:
                        if ani['title_english'] and not ap:
                            ap = AniP.getMangaURL(ani['title_english'])
                        if ani['title_romaji'] and not ap:
                            ap = AniP.getMangaURL(ani['title_romaji'])
                        if ani['synonyms'] and not ap:
                            for synonym in ani['synonyms']:
                                if ap:
                                    break
                                ap = AniP.getMangaURL(synonym)

                if (str(baseComment.subreddit).lower is not 'nihilate') and (
                        str(baseComment.subreddit).lower
                        is not 'roboragi') and not blockTracking:
                    DatabaseHandler.addRequest(titleToAdd, 'Manga',
                                               baseComment.author.name,
                                               baseComment.subreddit)
            except:
                traceback.print_exc()
                pass

        return CommentBuilder.buildMangaComment(isExpanded, mal, ani, mu, ap)

    except Exception as e:
        traceback.print_exc()
        return None
示例#4
0
def buildMangaReply(searchText, isExpanded, baseComment, blockTracking=False):
    try:
        ani = None
        mal = None
        mu = None
        ap = None
        
        try:
            sqlCur.execute('SELECT dbLinks FROM synonyms WHERE type = "Manga" and lower(name) = ?', [searchText.lower()])
        except sqlite3.Error as e:
            print(e)

        alternateLinks = sqlCur.fetchone()

        if (alternateLinks):
            synonym = json.loads(alternateLinks[0])       
            
            if (synonym['mal']):
                mal = MAL.getMangaDetails(synonym['mal'][0], synonym['mal'][1])
            if (synonym['ani']):
                ani = Anilist.getMangaDetailsById(synonym['ani'])
            if (synonym['mu']):
                mu = MU.getMangaURLById(synonym['mu'])
            if (synonym['ap']):
                ap = AniP.getMangaURLById(synonym['ap'])

        else:
            #Basic breakdown:
            #If Anilist finds something, use it to find the MAL version.
            #If hits either MAL or Ani, use it to find the MU version.
            #If it hits either, add it to the request-tracking DB.
            ani = Anilist.getMangaDetails(searchText)
            
            if not (ani is None):
                mal = MAL.getMangaDetails(ani['title_romaji'])

            else:
                mal = MAL.getMangaDetails(searchText)

                if not (mal is None):
                    ani = Anilist.getMangaDetails(mal['title'])    

        #----- Finally... -----#
        if ani or mal:
            try:
                titleToAdd = ''
                if mal:
                    titleToAdd = mal['title']
                else:
                    titleToAdd = ani['title_english']

                
                if not alternateLinks:
                    #MU stuff
                    if mal:
                        mu = MU.getMangaURL(mal['title'])
                    else:
                        mu = MU.getMangaURL(ani['title_romaji'])

                    #Do the anime-planet stuff
                    if mal and not ap:
                        if mal['title'] and not ap:
                            ap = AniP.getMangaURL(mal['title'])
                        if mal['english'] and not ap:
                            ap = AniP.getMangaURL(mal['english'])
                        if mal['synonyms'] and not ap:
                            for synonym in mal['synonyms']:
                                if ap:
                                    break
                                ap = AniP.getMangaURL(synonym)

                    if ani and not ap:
                        if ani['title_english'] and not ap:
                            ap = AniP.getMangaURL(ani['title_english'])
                        if ani['title_romaji'] and not ap:
                            ap = AniP.getMangaURL(ani['title_romaji'])
                        if ani['synonyms'] and not ap:
                            for synonym in ani['synonyms']:
                                if ap:
                                    break
                                ap = AniP.getMangaURL(synonym)

                if (str(baseComment.subreddit).lower is not 'nihilate') and (str(baseComment.subreddit).lower is not 'roboragi') and not blockTracking:
                    DatabaseHandler.addRequest(titleToAdd, 'Manga', baseComment.author.name, baseComment.subreddit)
            except:
                traceback.print_exc()
                pass
        
        return CommentBuilder.buildMangaComment(isExpanded, mal, ani, mu, ap)
        
    except Exception as e:
        traceback.print_exc()
        return None