from categories import get_categories
from xlsx_recorder import Recorder
from parser import get_parser
from extractor import get_extractor
import re

def main():
    # --- Настройки перед стартом ---
    print("Создавать JSON-файлы при парсинге? (0 = нет, 1 = да)")
    try_json = input("→ ") or "1"

    print("Отправлять JSON-файлы на API после создания? (0 = нет, 1 = да)")
    try_send = input("→ ") or "1"

    try_json = try_json.strip() == "1"
    try_send = try_send.strip() == "1"

    recorder = Recorder(try_json=try_json, try_send=try_send)

    try:
        extractor = get_extractor()
    except:
        raise Exception("Error: parse_settings")

    try:
        parser = get_parser()
    except:
        raise Exception("Error: request_settings")

    categories = get_categories()

    extractor.extract(parser, recorder, categories)

if __name__ == "__main__":
    main()
