<commit_before>import datetime

from django.utils import timezone
from celery.task.schedules import crontab
from celery.decorators import periodic_task

from .fetch_songs import fetch_songs_from_spreadsheet, fetch_youtube_metadata_for_songs
from .models import Song, Tag, SongUpdateToken


@periodic_task(run_every=(crontab(minute='*/30')), name="fetch_and_update_songs")
def fetch_and_update_songs():
    token = SongUpdateToken.objects.create(started=timezone.now())

    songs = fetch_songs_from_spreadsheet('https://spreadsheets.google.com/feeds/cells/' +
                                         '1HRfMfK1IF3sP9tTmBe_eXClBuG-Go9BCXmFK9oipSvA' +
                                         '/od6/public/values?alt=json-in-script')

    print('Fetched {} songs'.format(len(songs)))

    updated_songs = fetch_youtube_metadata_for_songs(songs)

    print('Got youtube metadata for {} songs'.format(len(updated_songs)))

    for song_dict in updated_songs:
        update_song_from_dict(song_dict)

    print('Updated Songs in Database')
<commit_msg>Updated task frequency to every hour<commit_after>import datetime

from django.utils import timezone
from celery.task.schedules import crontab
from celery.decorators import periodic_task

from .fetch_songs import fetch_songs_from_spreadsheet, fetch_youtube_metadata_for_songs
from .models import Song, Tag, SongUpdateToken


@periodic_task(run_every=(crontab(minute=0, hour='*/1')), name="fetch_and_update_songs")
def fetch_and_update_songs():
    token = SongUpdateToken.objects.create(started=timezone.now())

    songs = fetch_songs_from_spreadsheet('https://spreadsheets.google.com/feeds/cells/' +
                                         '1HRfMfK1IF3sP9tTmBe_eXClBuG-Go9BCXmFK9oipSvA' +
                                         '/od6/public/values?alt=json-in-script')

    print('Fetched {} songs'.format(len(songs)))

    updated_songs = fetch_youtube_metadata_for_songs(songs)

    print('Got youtube metadata for {} songs'.format(len(updated_songs)))

    for song_dict in updated_songs:
        update_song_from_dict(song_dict)

    print('Updated Songs in Database')

{'fraction_non_alphanumeric': 0.09501411100658513, 'fraction_numerical': 0.008466603951081843, 'mean_word_length': 3.912240184757506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5781542', 'n_tokens_mistral': 699, 'n_tokens_neox': 659, 'n_words': 112}