Added left calendar dates parsing
This commit is contained in:
36
main.py
36
main.py
@@ -15,6 +15,7 @@ import utils
|
||||
import json
|
||||
import links_parser
|
||||
import shutil
|
||||
import hashes
|
||||
|
||||
def currt():
|
||||
return round(time.time())
|
||||
@@ -25,7 +26,7 @@ FACULTETS = sorted([
|
||||
DIRNAME = "excels"
|
||||
DIFFABLE_DATES = "diffable_dates.txt"
|
||||
|
||||
DEBUG_ONE_FAC = None #'htf'
|
||||
DEBUG_ONE_FAC = None #'fevt'
|
||||
result_groups = {}
|
||||
result = {
|
||||
"version": 1,
|
||||
@@ -42,14 +43,14 @@ result = {
|
||||
"total_parsing_time": -1,
|
||||
},
|
||||
"api_notices": {
|
||||
"updated_at": 1757688552,
|
||||
"text": "Пожалуйста сохраняйте 'updated_at', это время изменения ЭТОГО текста. Тут возможно будут появлятся важные BREAKING CHANGES и дедлайны к ним.\nПо хорошему если updated_at другой по сравнению с вашем кэшем это сообщение должно отправляться вам в телеграм как уведомление о поедстоящих изменениях\nwarning=True значит 'text' содержит важное а не как щас hint.\n\n ~fazziclay aka Stanislav;",
|
||||
"updated_at": 1759651871,
|
||||
"text": "Пожалуйста сохраняйте 'updated_at', это время изменения ЭТОГО текста. Тут возможно будут появлятся важные BREAKING CHANGES и дедлайны к ним.\nПо хорошему если updated_at другой по сравнению с вашем кэшем это сообщение должно отправляться вам в телеграм как уведомление о поедстоящих изменениях\nwarning=True значит 'text' содержит важное а не как щас hint.\n\n ~fazziclay aka Stanislav;\n\n2025-10-05: добавлено data_source_hash в эксель и в группу. Это SHA1 of скачанный эксель файл.",
|
||||
"warning": False,
|
||||
"tut-plavayuschaya-struktura": "required only 'updated_at', 'text' and 'warning'"
|
||||
},
|
||||
"doubled_groups": [],
|
||||
"debug": {
|
||||
"bleu~~": 1
|
||||
"bleu~~": 2
|
||||
},
|
||||
"excels": [],
|
||||
"facultets": FACULTETS,
|
||||
@@ -66,22 +67,28 @@ result = {
|
||||
|
||||
def process_excel_file(facultet, excel_url, counter, latest_changed):
|
||||
is_xlsx = excel_url.endswith(".xlsx")
|
||||
filename = f"{DIRNAME}/" + f"_[C{counter}]_" + facultet + ".xls" + ("x" if is_xlsx else "")
|
||||
download_place = f"{DIRNAME}/" + f"_[C{counter}]_" + facultet + ".xls" + ("x" if is_xlsx else "")
|
||||
|
||||
excel_filename = excel_url.split("/")[-1]
|
||||
|
||||
excel_info = {
|
||||
"filename": excel_url.split("/")[-1],
|
||||
"filename": excel_filename,
|
||||
"data_source_hash": None,
|
||||
"url": excel_url,
|
||||
"latest_changed": latest_changed,
|
||||
"download_place": filename,
|
||||
"download_place": download_place,
|
||||
"group_names_parsed": [],
|
||||
"facultet": facultet,
|
||||
"counter": counter
|
||||
"counter": counter,
|
||||
"week_keys_metadata": {}
|
||||
}
|
||||
parser.LOGGING = False
|
||||
|
||||
try:
|
||||
aigenerated.download_file_from_url(excel_url, filename)
|
||||
reader = translations.create_reader(filename)
|
||||
aigenerated.download_file_from_url(excel_url, download_place)
|
||||
sha1hash = hashes.calculate_sha1(download_place)
|
||||
excel_info['data_source_hash'] = sha1hash
|
||||
reader = translations.create_reader(download_place)
|
||||
print("Reader info")
|
||||
print(reader.info())
|
||||
|
||||
@@ -95,6 +102,9 @@ def process_excel_file(facultet, excel_url, counter, latest_changed):
|
||||
print("parsed done!")
|
||||
if prs.parser_error is not None:
|
||||
excel_info["parser_error_cycle_" + str(reader.get_sheet_index()+1)] = prs.parser_error
|
||||
|
||||
if prs.parser_warnings is not None and len(prs.parser_warnings) > 0:
|
||||
excel_info["parser_warnings_cycle_" + str(reader.get_sheet_index()+1)] = prs.parser_warnings
|
||||
|
||||
for group_name in prs.groups.keys():
|
||||
if group_name in result_groups.keys():
|
||||
@@ -110,14 +120,16 @@ def process_excel_file(facultet, excel_url, counter, latest_changed):
|
||||
|
||||
gr = result_groups[group_name] = prs.groups[group_name]
|
||||
gr['facultet'] = facultet
|
||||
gr['data_source'] = excel_url.split("/")[-1]
|
||||
gr['data_source'] = excel_filename # same as 'filename' in excel_info's
|
||||
gr['data_source_hash'] = sha1hash
|
||||
gr['debug'] = {
|
||||
"excel_url": excel_url,
|
||||
"reader_info": reader.info(),
|
||||
"reader_sheet_index": reader.get_sheet_index(),
|
||||
"filename": filename
|
||||
"download_place": download_place
|
||||
}
|
||||
excel_info["group_names_parsed"].append(group_name)
|
||||
excel_info['week_keys_metadata'] = prs.week_keys_metadata
|
||||
|
||||
print(f"Populates {len(prs.groups)} groups to result: " + " ".join(prs.groups.keys()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user