<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple script for creating a Postgres database

This script invokes Postgres command line tools, specifically the "createdb" command.  The directory containing these
commands must be on your PATH for this script to work.

See the Postgres documentation for details on how to create databases.


Note that the name of the database to create is retrieved from the config.py file.
"""
from subprocess import call
from config import DB_NAME

create_db_cmd = 'createdb ' + DB_NAME

call('echo -n Creating database...', shell=True)
call(create_db_cmd, shell=True)
call('echo Done.', shell=True)<commit_msg>refactor pg database creation<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple script for creating a Postgres database

This script invokes Postgres command line tools, specifically the "createdb" command.  The directory containing these
commands must be on your PATH for this script to work.

See the Postgres documentation for details on how to create databases.


Note that the name of the database to create is retrieved from the config.py file.
"""
import logging
import psycopg2

logger = logging.getLogger('pygameday')


db_name = 'gameday'  # Database name to create
database_uri = 'postgresql://chris:chris@nas-1/postgres'  # Connection parameters


with psycopg2.connect(database_uri) as conn:
    conn.autocommit = True
    with conn.cursor() as cur:
        try:
            cur.execute('CREATE DATABASE {};'.format(db_name))
            logger.info('Created database')
        except Exception as ex:
            logger.exception('Error creating database', ex)

{'fraction_non_alphanumeric': 0.0856453558504222, 'fraction_numerical': 0.0030156815440289505, 'mean_word_length': 4.042553191489362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1837117', 'n_tokens_mistral': 461, 'n_tokens_neox': 444, 'n_words': 189}