Exemple #1
0
def buildVisualNovelReply(searchText,
                          isExpanded,
                          baseComment,
                          blockTracking=False):
    """ Builds an VN reply from VNDB """
    try:
        vndb = VNDB()

        try:
            query = ('SELECT dbLinks'
                     '  FROM synonyms'
                     ' WHERE type = "VN"'
                     '   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:
                if 'vndb' in synonym and synonym['vndb']:
                    synonym = synonym['vndb']

                if synonym:
                    result = vndb.getVisualNovelDetailsById(synonym)
                else:
                    result = None

        else:
            result = vndb.getVisualNovelDetails(searchText)

        vndb.close()

        if result:
            try:
                titleToAdd = result['title']

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

            return CommentBuilder.buildVisualNovelComment(isExpanded, result)
        else:
            print('No result found for ' + searchText)
            return None

    except Exception:
        traceback.print_exc()
        return None
Exemple #2
0
def buildVisualNovelReply(searchText,
                          isExpanded,
                          baseComment,
                          blockTracking=False):
    try:
        vndb = VNDB()

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

        alternateLinks = sqlCur.fetchone()

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

            if synonym:
                vndbsyn = None
                if 'vndb' in synonym and synonym['vndb']:
                    synonym = synonym['vndb']

                result = vndb.getVisualNovelDetailsById(
                    synonym) if synonym else None

        else:
            result = vndb.getVisualNovelDetails(searchText)

        vndb.close()

        if result:
            try:
                titleToAdd = result['title']

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

            return CommentBuilder.buildVisualNovelComment(isExpanded, result)
        else:
            print('No result found for ' + searchText)
            return None

    except Exception as e:
        traceback.print_exc()
        return None