Toot dates in french.
This commit is contained in:
parent
58e3060636
commit
12d3c3ddd4
|
@ -4,6 +4,7 @@ import argparse
|
|||
import logging
|
||||
import re
|
||||
import sqlite3
|
||||
import locale
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from time import sleep
|
||||
from pathlib import Path
|
||||
|
@ -141,16 +142,7 @@ def live_toot(talks, mastodon: Mastodon, ahead_days=0):
|
|||
for talk in talks:
|
||||
if talk.category == "Sprint":
|
||||
continue # We don't toot sprints.
|
||||
delta = (
|
||||
talk.start_date - datetime.now(timezone.utc) - timedelta(days=ahead_days)
|
||||
)
|
||||
if delta.total_seconds() < -300:
|
||||
logging.info("Skipping %s (already happened).", talk.title)
|
||||
continue
|
||||
if delta.total_seconds() > 10:
|
||||
logging.info("Waiting %s for %s to start.", delta, talk.title)
|
||||
sleep(delta.total_seconds() - 2) # Wait for the talk to start.
|
||||
sleep(2) # This is just a fool guard so we can Ctrl-C easily anytime.
|
||||
toot = toot_for(talk, ahead_days)
|
||||
png_name = f"talk-{talk.id}.png"
|
||||
with suppress(FileNotFoundError):
|
||||
Path(png_name).unlink()
|
||||
|
@ -164,8 +156,20 @@ def live_toot(talks, mastodon: Mastodon, ahead_days=0):
|
|||
),
|
||||
salle="Salle " + talk.room.split("/")[0],
|
||||
)
|
||||
delta = (
|
||||
talk.start_date - datetime.now(timezone.utc) - timedelta(days=ahead_days)
|
||||
)
|
||||
if delta.total_seconds() < -300:
|
||||
logging.info(
|
||||
"Skipping %s with image %s (already happened).", toot, png_name
|
||||
)
|
||||
continue
|
||||
if delta.total_seconds() > 10:
|
||||
logging.info("Waiting %s for %s to start.", delta, talk.title)
|
||||
sleep(delta.total_seconds() - 2) # Wait for the talk to start.
|
||||
sleep(2) # This is just a fool guard so we can Ctrl-C easily anytime.
|
||||
media = mastodon.media_post(png_name)
|
||||
mastodon.status_post(toot_for(talk, ahead_days), media_ids=[media])
|
||||
mastodon.status_post(toot, media_ids=[media])
|
||||
|
||||
|
||||
class DryRunMastodon:
|
||||
|
@ -189,6 +193,7 @@ class DryRunMastodon:
|
|||
|
||||
def main():
|
||||
args = parse_args()
|
||||
locale.setlocale(locale.LC_TIME, "fr_FR.UTF-8")
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
talks = get_talks(args.django_site_id)
|
||||
mastodon_instance = DryRunMastodon if args.dry_run else Mastodon
|
||||
|
|
Loading…
Reference in New Issue