<commit_before>from django.conf import settings

import json
import urllib
from os.path import join
from datetime import datetime, date, timedelta


def get_automation_id_choices():
    base_url = getattr(settings, 'AUTOMATION_BASE_URL', None)
    cache_dir = getattr(settings, 'AUTOMATION_CACHE_DIR', 'cache')
    cached_shows = join(cache_dir, 'shows.json')
    shows = []
    if base_url:
        try:
            shows_json = urllib.urlopen(base_url).read()
            shows_list = json.loads(shows_json)['shows']
        except IOError:
            try:
                with open(cached_shows) as cache:
                    shows_list = json.loads(cache.read())['shows']
            except IOError:
                shows_list = []
        else:
            with open(cached_shows, 'w') as cache:
                cache.write(shows_json)

        shows = [(s['id'], s['title']) for s in shows_list]
    return shows


def tofirstdayinisoweek(year, week):
    # http://stackoverflow.com/questions/5882405/get-date-from-iso-week-number-in-python
    ret = datetime.strptime('%04d-%02d-1' % (year, week), '%Y-%W-%w')
    if date(year, 1, 4).isoweekday() > 4:
        ret -= timedelta(days=7)
    return ret<commit_msg>added automation ID to list<commit_after>from django.conf import settings

import json
import urllib
from os.path import join
from datetime import datetime, date, timedelta


def get_automation_id_choices():
    base_url = getattr(settings, 'AUTOMATION_BASE_URL', None)
    cache_dir = getattr(settings, 'AUTOMATION_CACHE_DIR', 'cache')
    cached_shows = join(cache_dir, 'shows.json')
    shows = []
    if base_url:
        try:
            shows_json = urllib.urlopen(base_url).read()
            shows_list = json.loads(shows_json)['shows']
        except IOError:
            try:
                with open(cached_shows) as cache:
                    shows_list = json.loads(cache.read())['shows']
            except IOError:
                shows_list = []
        else:
            with open(cached_shows, 'w') as cache:
                cache.write(shows_json)

        shows = [(s['id'], '%d | %s' % (s['id'], s['title'])) for s in shows_list]
    return shows


def tofirstdayinisoweek(year, week):
    # http://stackoverflow.com/questions/5882405/get-date-from-iso-week-number-in-python
    ret = datetime.strptime('%04d-%02d-1' % (year, week), '%Y-%W-%w')
    if date(year, 1, 4).isoweekday() > 4:
        ret -= timedelta(days=7)
    return ret
{'fraction_non_alphanumeric': 0.12808080808080807, 'fraction_numerical': 0.01292929292929293, 'mean_word_length': 2.557471264367816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7612099', 'n_tokens_mistral': 840, 'n_tokens_neox': 814, 'n_words': 176}