Beispiel #1
0
def buildMangaReply(searchText, isExpanded, baseComment):
    try:
        #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)
        mal = None
        mu = None
        
        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'])

        if (ani is not None) or (mal is not None):
            try:
                titleToAdd = ''
                if mal is not None:
                    titleToAdd = mal['title']
                    mu = MU.getMangaURL(mal['title'])
                else:
                    titleToAdd = ani['title_english']
                    mu = MU.getMangaURL(ani['title_romaji'])

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

            if ani is not None:
                if ani['adult'] is True:
                    print("NSFW ENTRY")
                    mal = None
                    ani = None
                    mu = None
            
            return CommentBuilder.buildMangaComment(isExpanded, mal, ani, mu)
    
    except Exception as e:
        traceback.print_exc()
        return None
Beispiel #2
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
Beispiel #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'])
            if (synonym['ani']):
                ani = Anilist.getMangaDetails(synonym['ani'])
            if (synonym['mu']):
                mu = MU.getMangaURL(synonym['mu'])
            if (synonym['ap']):
                ap = AniP.getMangaURL(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

        if ani is not None:
            if ani['adult'] is True:
                mal = None
                ani = None
                mu = None
                ap = None
        
        return CommentBuilder.buildMangaComment(isExpanded, mal, ani, mu, ap)
        
    except Exception as e:
        traceback.print_exc()
        return None
Beispiel #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 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