2021-05-20 01:57:40 +02:00
|
|
|
import logging.config
|
|
|
|
|
2021-08-05 00:29:50 +02:00
|
|
|
|
2021-07-12 22:17:49 +02:00
|
|
|
from mobilizon_bots.event.event_selection_strategies import select_event_to_publish
|
2021-07-05 21:58:29 +02:00
|
|
|
from mobilizon_bots.mobilizon.events import get_unpublished_events
|
2021-08-05 00:29:50 +02:00
|
|
|
from mobilizon_bots.models.publication import PublicationStatus
|
2021-07-12 22:17:49 +02:00
|
|
|
from mobilizon_bots.publishers import get_active_publishers
|
|
|
|
from mobilizon_bots.publishers.coordinator import PublisherCoordinator
|
2021-08-05 00:29:50 +02:00
|
|
|
from mobilizon_bots.storage.query import (
|
|
|
|
get_published_events,
|
|
|
|
get_unpublished_events as get_db_unpublished_events,
|
|
|
|
create_unpublished_events,
|
|
|
|
save_publication_report,
|
|
|
|
publications_with_status,
|
|
|
|
)
|
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-08-04 18:53:58 +02:00
|
|
|
async def main():
|
2021-05-13 13:32:44 +02:00
|
|
|
"""
|
|
|
|
STUB
|
|
|
|
:return:
|
|
|
|
"""
|
2021-07-12 22:17:49 +02:00
|
|
|
|
|
|
|
active_publishers = get_active_publishers()
|
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-12 22:17:49 +02:00
|
|
|
# Store in the DB only the ones we didn't know about
|
2021-07-05 23:07:12 +02:00
|
|
|
await create_unpublished_events(unpublished_events, active_publishers)
|
2021-08-05 00:29:50 +02:00
|
|
|
event = select_event_to_publish(
|
|
|
|
published_events,
|
|
|
|
# We must load unpublished events from DB since it contains
|
|
|
|
# merged state between Mobilizon and previous WAITING events.
|
|
|
|
list(await get_db_unpublished_events()),
|
|
|
|
)
|
2021-07-12 22:17:49 +02:00
|
|
|
if event:
|
|
|
|
logger.debug(f"Event to publish found: {event.name}")
|
2021-08-05 00:29:50 +02:00
|
|
|
result = PublisherCoordinator(
|
|
|
|
event,
|
|
|
|
[
|
|
|
|
(pub.id, pub.publisher.name)
|
|
|
|
for pub in await publications_with_status(
|
|
|
|
status=PublicationStatus.WAITING,
|
|
|
|
event_mobilizon_id=event.mobilizon_id,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
).run()
|
|
|
|
await save_publication_report(result, event)
|
|
|
|
|
|
|
|
return 0 if result.successful else 1
|
2021-07-12 22:17:49 +02:00
|
|
|
else:
|
2021-08-05 00:29:50 +02:00
|
|
|
return 0
|