<commit_before>#!/usr/bin/env python3

import socket
import sys

from os import environ
from time import sleep
from urllib.parse import urlparse

o = urlparse(environ["DATABASE_URL"])
host = o.hostname
port = o.port or 5432

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
for i in range(10):
    try:
        s.connect((host, port))
        s.shutdown(socket.SHUT_RDWR)
        sys.exit(0)
    except Exception as e:
        print(e, file=sys.stderr)
        sleep(1)

print("Could not connect to {}:{}".format(host, port), file=sys.stderr)
sys.exit(1)<commit_msg>entrypoint: added simple fallback to get DATABASE_URL<commit_after>#!/usr/bin/env python3

import os
import socket
import sys

from os import environ
from time import sleep
from urllib.parse import urlparse

DATABASE_URL = None
try:
    DATABASE_URL = environ["DATABASE_URL"]
except KeyError:
    print("DATABASE_URL not defined as enviroment variable", file=sys.stderr)
    envfile = os.path.dirname(os.path.realpath(__file__)) + "/../.env"
    print("Trying to read from {}".format(envfile), file=sys.stderr)
    with open(envfile) as f:
        for line in f:
            if line.startswith("DATABASE_URL"):
                _, DATABASE_URL = line.strip().split('=', 1)

if not DATABASE_URL:
    print("DATABASE_URL not defined", file=sys.stderr)
    sys.exit(1)

o = urlparse(DATABASE_URL)
host = o.hostname
port = o.port or 5432

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
for i in range(10):
    try:
        s.connect((host, port))
        s.shutdown(socket.SHUT_RDWR)
        sys.exit(0)
    except Exception as e:
        print(e, file=sys.stderr)
        sleep(1)

print("Could not connect to {}:{}".format(host, port), file=sys.stderr)
sys.exit(1)
{'fraction_non_alphanumeric': 0.1242093156986774, 'fraction_numerical': 0.012650948821161587, 'mean_word_length': 3.416243654822335, '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': '7516700', 'n_tokens_mistral': 620, 'n_tokens_neox': 608, 'n_words': 157}