<commit_before>extern crate url;

use std::env;
use url::Url;

const POSTGRES_HOST: &'static str = env!("POSTGRES_HOST");
const POSTGRES_PORT: &'static str = env!("POSTGRES_PORT");
const POSTGRES_USER: &'static str = env!("POSTGRES_USER");
const POSTGRES_PASSWORD: &'static str = env!("POSTGRES_PASSWORD");
const POSTGRES_DATABASE: &'static str = env!("POSTGRES_DATABASE");

fn usage() {
    println!("\
URL Shortener

Usage:
  url_shortener <url>");
}

fn main() {
    let args: Vec<String> = env::args().collect();

    if args.len() != 2 {
        usage();
        return;
    }

    let url = Url::parse(&args[1]);

    if url.is_err() {
        usage();
        return;
    }

    let _url = url.unwrap();
}
<commit_msg>Add `connect()` function<commit_after>extern crate url;
extern crate postgres;

use std::env;
use url::Url;
use postgres::{Connection, SslMode};
use postgres::error::ConnectError;

const POSTGRES_HOST: &'static str = env!("POSTGRES_HOST");
const POSTGRES_PORT: &'static str = env!("POSTGRES_PORT");
const POSTGRES_USER: &'static str = env!("POSTGRES_USER");
const POSTGRES_PASSWORD: &'static str = env!("POSTGRES_PASSWORD");
const POSTGRES_DATABASE: &'static str = env!("POSTGRES_DATABASE");

fn usage() {
    println!("\
URL Shortener

Usage:
  url_shortener <url>");
}

fn main() {
    let args: Vec<String> = env::args().collect();

    if args.len() != 2 {
        usage();
        return;
    }

    let url = Url::parse(&args[1]);

    if url.is_err() {
        usage();
        return;
    }

    let _url = url.unwrap();
}

fn connect() -> Result<Connection, ConnectError> {
    let url = format!("postgres://{user}:{password}@{host}:{port}/{database}",
                        user = POSTGRES_USER, password = <PASSWORD>,
                        host = POSTGRES_HOST, port = POSTGRES_PORT,
                        database = POSTGRES_DATABASE);

    return Connection::connect(&*url, &SslMode::None);
}

{'fraction_non_alphanumeric': 0.16520392359318534, 'fraction_numerical': 0.002065049044914817, 'mean_word_length': 3.3846153846153846, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, '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': '4170733', 'n_tokens_mistral': 688, 'n_tokens_neox': 667, 'n_words': 152}