import asyncio
import logging
import os
import time
from datetime import datetime

from sqlmodel import Session, SQLModel, select
from starlette.concurrency import run_in_threadpool

from ..datatypes import ArtmuseumTimeLabel
from ..scraping.artmuseum import scrap_artmuseum
from ..scraping.philharmonia import scrap_philharmonia
from .models import ArtmuseumExhibition, PhilharmoniaConcert


def refresh_data(engine):
    """
    Scrap all the data sources for up-to-date info. Drop local values and replace them with the new data.

    We are trying to be an exact mirror of our data sources.
    The easiest way to achieve this is to regularly throw out all the data we have and scrap up-to-date info.
    The cost of this approach in performance/resources is neglectable and is much preffered over complications
    brought by trying to maintain a local copy by continuously patching it up with UPDATEs.
      (there can be edits in the source info, urls can change, etc. - it's not worth it to consider all such corner cases)
    """
    logging.info("Started scraping up-to-date info.")
    known_addrs = {}
    with Session(engine) as session:
        stmt = 