<commit_before>
import psycopg2

from bbox import Bbox


class PostgisDb(object):

    def __init__(self, log, host, port, user, passw, db):
        self.log = log
        self.connection = psycopg2.connect(
            database=db, user=user, password=<PASSWORD>, port=port, host=host)
        self.cursor = self.connection.cursor()

    def name_for_insee(self, insee):
        req = """
                        SELECT DISTINCT name
                        FROM planet_osm_polygon
                        WHERE tags->'ref:INSEE' = %s
                        AND admin_level = '8'
                        AND boundary = 'administrative'
              """
        self.cursor.execute(req, [insee])

        results = self.cursor.fetchall()
        assert(len(results) <= 1)
        return results[0][0] if len(results) else None

    def insee_for_name(self, name, interactive=True):
        req = """
                        SELECT tags->'ref:INSEE'
                        FROM planet_osm_polygon
                        WHERE admin_level = '8'
                        AND boundary = 'administrative'
                        AND name ILIKE %s || '%%'
              """
        self.cursor.execute(req, [name])

        results = [x[0] for x in self.cursor.fetchall()]

        if len(results) == 0:
            self.log.critical("Cannot found city with name {}.".format(name))
            exit(1)
        elif len(results) == 1:
            return results[0]
        elif len(results) > 30:
            self.log.critical(
                "Too many cities with name {} (total: {}). Please check name.".format(name, len(results)))
            exit(1)
        elif interactive:
            user_input = ''
            while user_input not in results:
                user_input = input(
                    "More than one city found. Please enter your desired one from the following list:\n\t{}\n".format('\n\t'.join(results)))
            return user_input

    def last_import_color(self, insee):
        req = """
                        SELECT TRIM(color)
                        FROM color_city
                        WHERE insee = %s
              """
        self.cursor.execute(req, [insee])

        results = self.cursor.fetchall()
        assert(len(results) <= 1)
        return results[0][0] if len(results) else None

    def last_import_author(self, insee):
        req = """
                        SELECT last_author
                        FROM color_city
                        WHERE insee = %s
                """<commit_msg>feat: display cities name on conflict<commit_after>
import psycopg2

from bbox import Bbox


class PostgisDb(object):

    def __init__(self, log, host, port, user, passw, db):
        self.log = log
        self.connection = psycopg2.connect(
            database=db, user=user, password=<PASSWORD>, port=port, host=host)
        self.cursor = self.connection.cursor()

    def name_for_insee(self, insee):
        req = """
                        SELECT DISTINCT name
                        FROM planet_osm_polygon
                        WHERE tags->'ref:INSEE' = %s
                        AND admin_level = '8'
                        AND boundary = 'administrative'
              """
        self.cursor.execute(req, [insee])

        results = self.cursor.fetchall()
        assert(len(results) <= 1)
        return results[0][0] if len(results) else None

    def insee_for_name(self, name, interactive=True):
        req = """
                        SELECT tags->'ref:INSEE', name
                        FROM planet_osm_polygon
                        WHERE admin_level = '8'
                        AND boundary = 'administrative'
                        AND name ILIKE %s || '%%'
              """
        self.cursor.execute(req, [name])

        results = [x for x in self.cursor.fetchall()]

        if len(results) == 0:
            self.log.critical("Cannot found city with name {}.".format(name))
            exit(1)
        elif len(results) == 1:
            return results[0][0]
        elif len(results) > 30:
            self.log.critical(
                "Too many cities with name {} (total: {}). Please check name.".format(name, len(results)))
            exit(1)
        elif interactive:
            user_input = ''
            while user_input not in [x[0] for x in results]:
                user_input = input(
                    "More than one city found. Please enter your desired one from the following list:\n\t{}\n".format('\n\t'.join(['{} - {}'.format(x[0], x[1]) for x in results])))
            return user_input

    def last_import_color(self, insee):
        req = """
                        SELECT TRIM(color)
                        FROM color_city
                        WHERE insee = %s
              """
        self.cursor.execute(req, [insee])

        results = self.cursor.fetchall()
        assert(len(results) <= 1)
        return results[0][0] if len(results) else None

    def last_import_author(self, insee):
        req = """
                        SELECT last_author
                        FROM color_city
                        WHERE insee = %s
                """
{'fraction_non_alphanumeric': 0.10718424101969873, 'fraction_numerical': 0.007531865585168019, 'mean_word_length': 1.4429245283018868, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1525523', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1352, 'n_words': 366}