2021-05-20 01:57:40 +02:00
|
|
|
import logging.config
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from tortoise import run_async
|
|
|
|
|
|
|
|
from mobilizon_bots.config.config import settings
|
2021-07-05 23:07:12 +02:00
|
|
|
|
|
|
|
from mobilizon_bots.config.publishers import get_active_publishers
|
|
|
|
from mobilizon_bots.event.event_selector import EventSelector, SelectNextEventStrategy
|
2021-07-05 21:58:29 +02:00
|
|
|
from mobilizon_bots.mobilizon.events import get_unpublished_events
|
2021-05-13 13:32:44 +02:00
|
|
|
from mobilizon_bots.storage.db import MobilizonBotsDB
|
2021-07-05 23:07:12 +02:00
|
|
|
from mobilizon_bots.storage.query import get_published_events, create_unpublished_events
|
|
|
|
from mobilizon_bots.storage.query import (
|
|
|
|
get_unpublished_events as get_db_unpublished_events,
|
|
|
|
)
|
2021-05-13 13:32:44 +02:00
|
|
|
|
2021-05-20 01:57:40 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2021-05-13 13:32:44 +02:00
|
|
|
|
2021-05-20 01:57:40 +02:00
|
|
|
async def main():
|
2021-05-13 13:32:44 +02:00
|
|
|
"""
|
|
|
|
STUB
|
|
|
|
:return:
|
|
|
|
"""
|
2021-05-20 01:57:40 +02:00
|
|
|
logging.config.dictConfig(settings.logging)
|
2021-07-05 23:07:12 +02:00
|
|
|
active_publishers = get_active_publishers(settings)
|
|
|
|
|
2021-05-20 01:57:40 +02:00
|
|
|
db = MobilizonBotsDB(Path(settings.db_path))
|
|
|
|
await db.setup()
|
2021-07-05 23:07:12 +02:00
|
|
|
|
|
|
|
# Load past events
|
|
|
|
published_events = list(await get_published_events())
|
|
|
|
|
|
|
|
# Pull unpublished events from Mobilizon
|
2021-05-30 21:47:36 +02:00
|
|
|
unpublished_events = get_unpublished_events(published_events)
|
2021-07-05 23:07:12 +02:00
|
|
|
# Store in the DB only the ones we din't know about
|
|
|
|
await create_unpublished_events(unpublished_events, active_publishers)
|
|
|
|
unpublished_events = list(await get_db_unpublished_events())
|
|
|
|
|
|
|
|
event_selector = EventSelector(
|
|
|
|
unpublished_events=unpublished_events, published_events=published_events
|
|
|
|
)
|
|
|
|
# TODO: Here we should somehow handle publishers
|
|
|
|
strategy = SelectNextEventStrategy(minimum_break_between_events_in_minutes=360)
|
|
|
|
event = event_selector.select_event_to_publish(strategy)
|
|
|
|
|
2021-05-13 13:32:44 +02:00
|
|
|
result = PublisherCoordinator(event).publish() if event else exit(0)
|
|
|
|
exit(0 if result.is_success() else 1)
|
2021-05-20 01:57:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
run_async(main())
|