<commit_before># -*- coding: utf-8 -*-
import json
import sqlite3
import requests


def schedule_update(db_path="Bot_db"):
    sql_con = sqlite3.connect(db_path)
    cursor = sql_con.cursor()
    # WITH construction doesn't work :(
    cursor.execute("""DELETE
                      FROM groups_data
                      WHERE id in (
                        SELECT
                          groups_data.id
                        FROM groups_data
                          LEFT OUTER JOIN user_data
                            ON groups_data.id = user_data.group_id
                        WHERE user_data.id ISNULL
                      )""")
    sql_con.commit()
    cursor.execute("""SELECT id FROM groups_data""")
    groups = cursor.fetchall()
    for group in groups:
        group_id = group[0]
        url = "https://timetable.spbu.ru/api/v1/groups/{0}/events".format(
            group_id)
        json_week_data = requests.get(url).json()
        data = json.dumps(json_week_data)
        cursor.execute("""UPDATE groups_data
                          SET json_week_data = ?
                          WHERE id = ?""",
                       (data, group_id))<commit_msg>bug fixes<commit_after># -*- coding: utf-8 -*-
import json
import sqlite3
import requests


def schedule_update(db_path="Bot_db"):
    sql_con = sqlite3.connect(db_path)
    cursor = sql_con.cursor()
    # WITH construction doesn't work :(
    cursor.execute("""DELETE
                      FROM groups_data
                      WHERE id in (
                        SELECT
                          groups_data.id
                        FROM groups_data
                          LEFT OUTER JOIN user_data
                            ON groups_data.id = user_data.group_id
                          LEFT OUTER JOIN user_groups
                            ON groups_data.id = user_groups.group_id
                        WHERE user_data.id ISNULL
                          AND user_groups.group_id ISNULL
                      )""")
    sql_con.commit()
    cursor.execute("""SELECT id FROM groups_data""")
    groups = cursor.fetchall()
    for group in groups:
        group_id = group[0]
        url = "https://timetable.spbu.ru/api/v1/groups/{0}/events".format(
            group_id)
        json_week_data = requests.get(url).json()
        data = json.dumps(json_week_data)
        cursor.execute("""UPDATE groups_data
                          SET json_week_data = ?
                          WHERE id = ?""",
                       (data, group_id))
{'fraction_non_alphanumeric': 0.089728453364817, 'fraction_numerical': 0.004722550177095631, 'mean_word_length': 1.3537037037037036, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6763885', 'n_tokens_mistral': 695, 'n_tokens_neox': 659, 'n_words': 144}