<commit_before># articles.py
# Article pages for CedarRapidsOnline web service
# Copyright (C) 2009 Clear Perception Solutions, LLC.
# Written by <NAME> <<EMAIL>>
# 
# This file is part of the CedarRapidsOnline web service.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import cherrypy
import pgdb
import string
import sqlutils
import pageutils
import time

database_connect_fields = sqlutils.database_connect_fields

class ArticlesPage:
    def index (self, article_slug=None):
        # If article_slug is None, display main article table of contents.
        # Else, display specified article.
        # Available to all, logged in or not.

        if (article_slug == None):
            article_slug = "map"

        description = None
        results = None
        comments_description = None
        comments_results = None
        author_results = []
        author_description = None
        # Try to connect to the database.
        try:
            dbconnection = pgdb.connect (database_connect_fields)
            dbcursor = dbconnection.cursor()
            dbcursor.execute ("SELECT * FROM articles WHERE slug=%s", [article_slug])
            # Get the cursor description and results from the query.
            description = dbcursor.description
            results = dbcursor.fetchone()

            # Get any comments for the article.
            if (results <> None):
                dbcursor.execute ("SELECT * FROM articles WHERE refers_to=%s",
                                  [str(results[sqlutils.getfieldindex ("article_id", description)])])
                comments_description = dbcursor.description
                comments_results = dbcursor.fetchall()
                for result in comments_results:
                    dbcursor.execute ("SELECT * FROM users WHERE user_id=%s",
                                      [str(result[sqlutils.getfieldindex ("author_id", comments_description)])])
                    author_description = dbcursor.description
                    author_results.append (dbcursor.fetchone())

            # Close the database cursor and connection.
            dbcursor.close()
            dbconnection.close()
        except:
            pass

        if (results == None):
            pass

        # Obtain the article title from the database results.
        pagetitle = ""
        try:
            pagetitle += results[sqlutils.getfieldindex ("title", description)]
        except:
            pagetitle = "Database Error."

        # Obtain the article body from the database results.
        pagetext = ""
        try:
            pagetext += results[sqlutils.getfieldindex ("body", description)]
        except:
            pagetext += "<p>Database Error.</p>"

        # Do we want to show comments on this page?
        if (int(results[sqlutils.getfieldindex ("display", description)]) > 1):
            pagetext += "<h3>Comments</h3>"
            if (comments_results <> None):
                for result in comments_results:
                    pagetext += "<p>"
                    pagetext += result[sqlutils.getfieldindex ("body", comments_description)]
                    for author in author_results:
                        if author[0] == result[sqlutils.getfieldindex ("author_id", comments_description)]:
                            pagetext += "<p><i>posted by " + author[sqlutils.getfieldindex ("name", author_description)]
                            pagetext += "on " + time.ctime(
                                result[sqlutils.getfieldindex ("creation_date", comments_description)]) + "</p>\n"
                    pagetext += "</p>"
            if (pageutils.is_logged_in_p()):
                pagetext += "<p><a href=\"/articles/comment/" + article_slug + "\">Add a comment</a></p>\n"
            else:
                pagetext += "<p><a href=\"/login\">Log in</a> to add a comment</a></p>\n"

        # Build the whole page and return it.
        return pageutils.generate_page (pagetitle, pagetext)<commit_msg>fixed typo<commit_after># articles.py
# Article pages for CedarRapidsOnline web service
# Copyright (C) 2009 Clear Perception Solutions, LLC.
# Written by <NAME> <<EMAIL>>
# 
# This file is part of the CedarRapidsOnline web service.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import cherrypy
import pgdb
import string
import sqlutils
import pageutils
import time

database_connect_fields = sqlutils.database_connect_fields

class ArticlesPage:
    def index (self, article_slug=None):
        # If article_slug is None, display main article table of contents.
        # Else, display specified article.
        # Available to all, logged in or not.

        if (article_slug == None):
            article_slug = "map"

        description = None
        results = None
        comments_description = None
        comments_results = None
        author_results = []
        author_description = None
        # Try to connect to the database.
        try:
            dbconnection = pgdb.connect (database_connect_fields)
            dbcursor = dbconnection.cursor()
            dbcursor.execute ("SELECT * FROM articles WHERE slug=%s", [article_slug])
            # Get the cursor description and results from the query.
            description = dbcursor.description
            results = dbcursor.fetchone()

            # Get any comments for the article.
            if (results <> None):
                dbcursor.execute ("SELECT * FROM articles WHERE refers_to=%s",
                                  [str(results[sqlutils.getfieldindex ("article_id", description)])])
                comments_description = dbcursor.description
                comments_results = dbcursor.fetchall()
                for result in comments_results:
                    dbcursor.execute ("SELECT * FROM users WHERE user_id=%s",
                                      [str(result[sqlutils.getfieldindex ("author_id", comments_description)])])
                    author_description = dbcursor.description
                    author_results.append (dbcursor.fetchone())

            # Close the database cursor and connection.
            dbcursor.close()
            dbconnection.close()
        except:
            pass

        if (results == None):
            pass

        # Obtain the article title from the database results.
        pagetitle = ""
        try:
            pagetitle += results[sqlutils.getfieldindex ("title", description)]
        except:
            pagetitle = "Database Error."

        # Obtain the article body from the database results.
        pagetext = ""
        try:
            pagetext += results[sqlutils.getfieldindex ("body", description)]
        except:
            pagetext += "<p>Database Error.</p>"

        # Do we want to show comments on this page?
        if (int(results[sqlutils.getfieldindex ("display", description)]) > 1):
            pagetext += "<h3>Comments</h3>"
            if (comments_results <> None):
                for result in comments_results:
                    pagetext += "<p>"
                    pagetext += result[sqlutils.getfieldindex ("body", comments_description)]
                    for author in author_results:
                        if author[0] == result[sqlutils.getfieldindex ("author_id", comments_description)]:
                            pagetext += "<p><i>posted by " + author[sqlutils.getfieldindex ("name", author_description)]
                            pagetext += "on " + time.ctime(
                                float(result[sqlutils.getfieldindex ("creation_date", comments_description)])) + "</p>\n"
                    pagetext += "</p>"
            if (pageutils.is_logged_in_p()):
                pagetext += "<p><a href=\"/articles/comment/" + article_slug + "\">Add a comment</a></p>\n"
            else:
                pagetext += "<p><a href=\"/login\">Log in</a> to add a comment</a></p>\n"

        # Build the whole page and return it.
        return pageutils.generate_page (pagetitle, pagetext)
{'fraction_non_alphanumeric': 0.09126551949466347, 'fraction_numerical': 0.001960357220649096, 'mean_word_length': 2.1319918144611187, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '853895', 'n_tokens_mistral': 2337, 'n_tokens_neox': 2255, 'n_words': 774}