<commit_before>#!/usr/bin/env python
from __future__ import print_function

from argparse import ArgumentParser
from datetime import (
    datetime,
    timedelta,
    )
import json
import os
import subprocess
import sys


def list_old_juju_containers(hours):
    env = dict(os.environ)
    containers = json.loads(subprocess.check_output([
        'lxc', 'list', '--format', 'json'], env=env))
    now = datetime.now()
    for container in containers:
        name = container['name']
        if not name.startswith('juju-'):
            continue
        # This produces local time.  lxc does not respect TZ=UTC.
        created_at = datetime.strptime(
            container['created_at'][:-6], '%Y-%m-%dT%H:%M:%S')
        age = now - created_at
        if age <= timedelta(hours=hours):
            continue
        yield name, age


def main():
    parser = ArgumentParser('Delete old juju containers')<commit_msg>Use dateutil to calculate age of container.<commit_after>#!/usr/bin/env python
from __future__ import print_function

from argparse import ArgumentParser
from datetime import (
    datetime,
    timedelta,
    )
import json
import os
import subprocess
import sys

from dateutil import (
    parser as date_parser,
    tz,
    )


def list_old_juju_containers(hours):
    env = dict(os.environ)
    containers = json.loads(subprocess.check_output([
        'lxc', 'list', '--format', 'json'], env=env))
    now = datetime.now(tz.gettz('UTC'))
    for container in containers:
        name = container['name']
        if not name.startswith('juju-'):
            continue
        created_at = date_parser.parse(container['created_at'])
        age = now - created_at
        if age <= timedelta(hours=hours):
            continue
        yield name, age


def main():
    parser = ArgumentParser('Delete old juju containers')
{'fraction_non_alphanumeric': 0.10917979359043997, 'fraction_numerical': 0.0005431830526887561, 'mean_word_length': 2.845511482254697, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2518842', 'n_tokens_mistral': 555, 'n_tokens_neox': 541, 'n_words': 153}