import requests
import time
import unittest
import telebot
from functions import create_schedule_answer
from constants import my_id


def everything_ok():
    return "OK", True


def get_all_aliases():
    aliases = []
    url = "https://timetable.spbu.ru/api/v1/divisions"
    data = requests.get(url).json()
    for alias in data:
        aliases.append(alias["Alias"])
    return aliases


def all_group_ids_for_alias(alias):
    group_ids = []
    url = "https://timetable.spbu.ru/api/v1/{}/studyprograms".format(alias)
    study_programs_data = requests.get(url).json()
    for study_program in study_programs_data:
        for study_program_combination in study_program[
             "StudyProgramCombinations"]:
            for admission_year in study_program_combination["AdmissionYears"]:
                if not admission_year["IsEmpty"]:
                    study_program_id = admission_year["StudyProgramId"]
                    url = "https://timetable.spbu.ru/api/v1/{}/studyprogram" \
                          "/{}/studentgroups".format(alias, study_program_id)
                    groups_data = requests.get(url).json()
                    for group in groups_data:
                        group_ids.append(group["StudentGroupId"])
                time.sleep(0)
    print(alias, "Done")
    return group_ids


def get_group_week_schedules(alias, group_id):
    answers = []
    url = "https://timetable.spbu.ru/api/v1/{}/studentgroup/{}/" \
          "events".format(alias, group_id)
    json_data = requests.get(url).json()
    for day_info in json_data["Days"]:
        answer = create_schedule_answer(day_info, full_place=True,
                                        personal=False)
        answers.append(answer)
    return answers


def get_all_schedules():
    all_answer = []
    for alias in get_all_aliases():
        for group_id in all_group_ids_for_alias(alias):
            all_answer.append(get_group_week_schedules(alias, group_id))
    return all_answer


def print_all():
    for group_schedules in get_all_schedules():
        for schedule in group_schedules:
            print(schedule)
        print("===============================\n")
    return True


class TestStringMethods(unittest.TestCase):

    def test_all(self):
        tb = telebot.TeleBot(test_token)
        msg = tb.send_message(my_id, "test", disable_notification=True)
        self.assertTrue(msg)


if __name__ == '__main__':
    unittest.main()

@@ -41,23 +41,8 @@
 est%0A
-import telebot%0A
 from
@@ -86,36 +86,8 @@
 wer%0A
-from constants import my_id%0A
 %0A%0Ade
@@ -1229,9 +1229,9 @@
 eep(
-0
+1
 )%0A  
@@ -2186,17 +2186,16 @@
 tCase):%0A
-%0A
     def 
@@ -2203,131 +2203,21 @@
 est_
-all(self):%0A        tb = telebot.TeleBot(test_token)%0A        msg = tb.send_message(my_id, %22test%22, disable_notification=True)
+string(self):
 %0A   
@@ -2236,16 +2236,26 @@
 sert
-True(msg
+Equal(%22AAA%22, %22AAA%22
 )%0A%0A%0A

create test