<commit_before>import pytz
from datetime import datetime
from os import path
import json


def get_lots_from_json(city, lot_name):
    """
    Get the total value from the highest known value in the last saved JSON file.
    This is useful for cities that don't publish total number of spaces for a parking lot.

    Caveats:
     - Returns 0 if not found.
     - If a lot name exists twice only the last value is returned.

    :param city:
    :param lot_name:
    :return:
    """
    lots = 0
    last_values_json_path = path.join("cache", city + ".json")
    if path.isfile(last_values_json_path):
        with open(last_values_json_path) as data_file:
            last_values = json.load(data_file)
            if last_values is None:
                # if no last json file exists, return 0
                return 0
            for lastlots in last_values["lots"]:
                if lastlots["name"] is lot_name:
                    lots = int(lastlots["total"])
    return lots


def utc_now():
    """
    Returns the current UTC time in ISO format.

    :return:
    """<commit_msg>Rewrote get most lots util function for DB<commit_after>import pytz
from datetime import datetime
from os import path
import json
import psycopg2
import configparser


def get_most_lots_from_json(city, lot_name):
    """
    Get the total value from the highest known value in the last saved JSON.
    This is useful for cities that don't publish total number of spaces for a parking lot.

    Caveats:
     - Returns 0 if not found.
     - If a lot name exists twice only the last value is returned.

    :param city:
    :param lot_name:
    :return:
    """

    config = configparser.ConfigParser()
    config.read("config.ini")
    db_data = {
        "host": config["Database"]["host"],
        "name": config["Database"]["name"],
        "user": config["Database"]["user"],
        "pass": config["Database"]["pass"],
        "port": config["Database"]["port"]
    }
    with psycopg2.connect(database=db_data["name"], user=db_data["user"], host=db_data["host"], port=db_data["port"],
                          password=db_data["pass"]) as conn:
        cursor = conn.cursor()
        cursor.execute("SELECT data FROM parkapi_test WHERE city=%s;", (city,))
        all_data = cursor.fetchall()

        most_lots = 0
        for json_data in all_data:
            lots = json_data[0]["lots"]
            for lot in lots:
                if lot["name"] == lot_name:
                    if int(lot["total"]) > most_lots:
                        most_lots = int(lot["total"])
        return most_lots


def utc_now():
    """
    Returns the current UTC time in ISO format.

    :return:
    """
{'fraction_non_alphanumeric': 0.10330732069862504, 'fraction_numerical': 0.0033444816053511705, 'mean_word_length': 2.3819095477386933, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 4, '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': '2777955', 'n_tokens_mistral': 796, 'n_tokens_neox': 780, 'n_words': 265}