<commit_before>import os
import re
import time
import subprocess

""" Download The Economist and send to kindle if new.

    Run in cron with the appropriate directory set:
    cd /home/noel/tmp/books && ./fetch_economist.py
"""

def fetch():
    url = ('https://raw.githubusercontent.com/kovidgoyal/calibre/master/' +
           'recipes/economist.recipe')
    cmd_1 = ['curl', url, '>', 'economist.recipe']
    subprocess.run(cmd_1, check=True)

    cmd_2 = ['ebook-convert', 'economist.recipe', 'economist.mobi']
    output = subprocess.run(cmd_2, stdout=subprocess.PIPE, check=True)

    for line in output:
        match = re.search(r'Got cover.*/(\d{8})', s)
        if match:
            date = match.group()
            break

    return 'economist.{}.mobi'.format(date)


def main():
    while True:
        dated_filename = fetch()

        if os.path.exists(dated_filename):
            time.sleep(5 * 60)
        else:
            open(dated_filename, 'a').close()
            subprocess.run([
                'calibre-smtp', '-a', 'economist.mobi', '-u',
                '<EMAIL>', '-p', 'PASSWORD', '-r',
                'smtp.PROVIDER.com', '--port', '587',
                '<EMAIL>', '<EMAIL>'])
            return

        if time.localtime().tm_hour > 22:
            return


if __name__ == '__main__':
    main()<commit_msg>Loop until getting new edition<commit_after>import os
import re
import time
import subprocess

""" Download The Economist and send to kindle if new """

def fetch():
    url = ('https://raw.githubusercontent.com/kovidgoyal/calibre/master/' +
           'recipes/economist.recipe')
    cmd_1 = ['curl', url, '>', 'economist.recipe']
    subprocess.run(cmd_1, check=True)

    cmd_2 = ['ebook-convert', 'economist.recipe', 'economist.mobi']
    output = subprocess.run(cmd_2, stdout=subprocess.PIPE, check=True)

    for line in output:
        match = re.search(r'Got cover.*/(\d{8})', s)
        if match:
            date = match.group()
            break

    return 'economist.{}.mobi'.format(date)


def main():
    while True:
        dated_filename = fetch()

        if os.path.exists(dated_filename):
            # The links are still being updated
            # Wait and retry in a few minutes
            time.sleep(5 * 60)
        else:
            open(dated_filename, 'a').close()
            subprocess.run([
                'calibre-smtp', '-a', 'economist.mobi',
                '-u', '<EMAIL>',
                '-p', 'PASSWORD',
                '-r', 'smtp.PROVIDER.com',
                '--port', '587',
                '<EMAIL>',
                '<EMAIL>'])
            return

        if time.localtime().tm_hour > 22:
            return


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.15067493615468808, 'fraction_numerical': 0.009485589201021525, 'mean_word_length': 2.00328587075575, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4637290', 'n_tokens_mistral': 902, 'n_tokens_neox': 864, 'n_words': 201}