def init(self, app_id, address, port, user_name, password, use_cache, epg_of_days):
		helper.log_info('DataProvider.init. %s %s %s %s %s %s %s' % (app_id, address, port, user_name, password, use_cache, epg_of_days))
		self.use_cache_ = use_cache
		self.app_id_ = app_id
		self.address_ = address
		self.epg_of_days_ = epg_of_days
		self.http_data_provider_ = HttpDataProvider(address, port, user_name, password)
		self.reset_()
def get_all_groups():
    log_info("Получение списка групп с расписанием...")

    result = []
    groups_xml = ET.fromstring(get_page(GROUPS_LIST_URL))
    for current_group in groups_xml.iter('studentGroup'):
        result.append((current_group.find('id').text, current_group.find('name').text))

    return result
def download_timetable(cache_path):
    try:
        timetable_db = shelve.open(cache_path, writeback=True)
    except OSError as e:
        fatal_error("Не удалось использовать базу: {}".format(e.strerror))
        return

    try:
        groups = sorted(get_all_groups(), key=lambda x: x[1])
        total_number = len(groups)
        log_info('{} - {}'.format(TOTAL_DECS, total_number))

        loaded_number = [x[1] for x in groups].index(max(timetable_db.keys())) + 1 if len(timetable_db) else 0
        log_info('{} - {}'.format(LOADED_DECS.rjust(len(TOTAL_DECS)), str(loaded_number).rjust(len(str(total_number)))))

        groups = groups[loaded_number:]

        for group_id, group_name in groups:
            log_info(r'{}/{}'.format(str(loaded_number + 1).rjust(len(str(total_number))), total_number))
            timetable_db[group_name] = parse_group_timetable(ET.fromstring(load_group_timetable(group_id)))
            loaded_number += 1
    except (ConnectionError, TimeoutError, urllib.error.HTTPError, urllib.error.URLError):
        fatal_error('Невозможно загрузить данные. Проверьте соединение с интернетом!')
    finally:
        timetable_db.close()
def build_auditoriums_busyness(timetable_db_path):
    log_info('Обработка расписания...')

    timetable_db = shelve.open(timetable_db_path)

    result = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(list)))))

    for group_name in timetable_db:
        for day_timetable in timetable_db[group_name]:
            for lesson in day_timetable['lessons']:
                if 'auditory' not in lesson:
                    continue
                for week_number in lesson['week_numbers']:
                    lesson_info = result[lesson['auditory']] \
                        [day_timetable['week_day']] \
                        [week_number] \
                        [lesson['lesson_time']]

                    lesson_info['groups'].append(group_name)
                    lesson_info['employee'] = lesson['employee']
                    lesson_info['subject'] = lesson['subject']

    return result
def write_result(busyness, result_file):
    days_list = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота']

    try:
        log_info('Запись результата...\n')
        f = open(result_file, 'w', encoding='utf-8')

        for auditorium in sorted(busyness.keys(), key=lambda x: (x[1], x[0])):
            f.write('{}-{}:\n'.format(auditorium[0], auditorium[1]))
            for week_day in sorted(busyness[auditorium], key=lambda x: days_list.index(x)):
                f.write('\t{}:\n'.format(week_day))
                for week_number in busyness[auditorium][week_day]:
                    f.write('\t\tнеделя {}\n'.format(week_number))
                    for lesson_time in sorted(busyness[auditorium][week_day][week_number], key=lambda x: x[1]):
                        lesson_info = busyness[auditorium][week_day][week_number][lesson_time]

                        f.write('\t' * 3 + '{}\n'.format(repr_lesson_time(lesson_time)))
                        f.write('\t' * 4 + 'предмет: {}\n'.format(lesson_info['subject']))
                        f.write('\t' * 4 + 'преподаватель: {}\n\n'.format(repr_employee(lesson_info['employee'])))

                        for group in sorted(lesson_info['groups']):
                            f.write('\t' * 4 + 'группа {}\n'.format(group))
    except OSError as e:
        fatal_error("Не удалось записать результат: {}".format(e.strerror))
def get_page(url):
    log_info('Загрузка ' + url + '...')
    return request.urlopen(url).read()