<commit_before>import argparse
import datetime
import json
import subprocess

import psycopg2


parser = argparse.ArgumentParser(
    description="Create a GeoJSON from a PostGIS query.",
    epilog="Example usage: python postgis2geojson.py -d awesomeData -h localhost -u user -p securePassword -t table -f id name geom -w 'columnA = columnB' -o myData --topojson")

parser.add_argument("-d", "--database", dest="database",
    type=str, required=True,
    help="The database to connect to")

# Python doesn't let you use -h as an option for some reason
parser.add_argument("-H", "--host", dest="host",
    default="localhost", type=str,
    help="Database host. Defaults to 'localhost'")

parser.add_argument("-u", "--user", dest="user",
    default="postgres", type=str,
    help="Database user. Defaults to 'postgres'")

parser.add_argument("-p", "--password", dest="password",
    type=str, required=True,
    help="Password for the database user")

parser.add_argument("-t", "--table", dest="table",
    type=str, required=True,
    help="Database table to query")

parser.add_argument("-f", "--fields", dest="fields",
    nargs="+",
    help="Fields to return separated by a single space. Defaults to *")

parser.add_argument("-g", "--geometry", dest="geometry",
    default="geom", type=str, 
    help="Name of the geometry column. Defaults to 'geom'")

parser.add_argument("-w", "--where", dest="where",
    type=str,
    help="Optional WHERE clause to add to the SQL query")

parser.add_argument("-o", "--output", dest="file",
    default="data", type=str,
    help="Output file name without extension. Defaults to 'data.geojson'")

parser.add_argument("--topojson", dest="topojson",
    action="store_true",
    help="Use if you would also like a copy of the data as TopoJSON")

parser.add_argument("--pretty", dest="pretty",
    action="store_true",
    help="Pretty print the output (indent).")

arguments = parser.parse_args()

def getData():
    # Connect to the database
    try:
        conn = psycopg2.connect("dbname=" + arguments.database + " user=" + arguments.user + " host=" + arguments.host + " password="+ arguments.password)
    except:
        print "Unable to connect to the database. Please check your options and try again."
        return
<commit_msg>Don't require password and add port option<commit_after>import argparse
import datetime
import json
import subprocess

import psycopg2


parser = argparse.ArgumentParser(
    description="Create a GeoJSON from a PostGIS query.",
    epilog="Example usage: python postgis2geojson.py -d awesomeData -h localhost -u user -p securePassword -t table -f id name geom -w 'columnA = columnB' -o myData --topojson")

parser.add_argument("-d", "--database", dest="database",
    type=str, required=True,
    help="The database to connect to")

# Python doesn't let you use -h as an option for some reason
parser.add_argument("-H", "--host", dest="host",
    default="localhost", type=str,
    help="Database host. Defaults to 'localhost'")

parser.add_argument("-u", "--user", dest="user",
    default="postgres", type=str,
    help="Database user. Defaults to 'postgres'")

parser.add_argument("-p", "--password", dest="password",
    default="", type=str,
    help="Password for the database user")

parser.add_argument("-P", "--port", dest="port",
    default="5432", type=str,
    help="Password for the database user")

parser.add_argument("-t", "--table", dest="table",
    type=str, required=True,
    help="Database table to query")

parser.add_argument("-f", "--fields", dest="fields",
    nargs="+",
    help="Fields to return separated by a single space. Defaults to *")

parser.add_argument("-g", "--geometry", dest="geometry",
    default="geom", type=str, 
    help="Name of the geometry column. Defaults to 'geom'")

parser.add_argument("-w", "--where", dest="where",
    type=str,
    help="Optional WHERE clause to add to the SQL query")

parser.add_argument("-o", "--output", dest="file",
    default="data", type=str,
    help="Output file name without extension. Defaults to 'data.geojson'")

parser.add_argument("--topojson", dest="topojson",
    action="store_true",
    help="Use if you would also like a copy of the data as TopoJSON")

parser.add_argument("--pretty", dest="pretty",
    action="store_true",
    help="Pretty print the output (indent).")

arguments = parser.parse_args()

def getData():
    # Connect to the database
    try:
        conn = psycopg2.connect("dbname=" + arguments.database + " user=" + arguments.user + " host=" + arguments.host + " port=" + arguments.port + " password="+ arguments.password)
    except:
        print "Unable to connect to the database. Please check your options and try again."
        return

{'fraction_non_alphanumeric': 0.15235281705001055, 'fraction_numerical': 0.002110149820637265, 'mean_word_length': 4.053304904051172, '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': '612392', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1413, 'n_words': 448}