masto-bridges/masto_bridges/main.py

53 lines
1.3 KiB
Python
Raw Normal View History

import pdb
2022-11-08 03:13:35 +00:00
from typing import Optional
from masto_bridges.config import Config
from masto_bridges.repo import Repo
from masto_bridges.bot import Bot
from masto_bridges.post import Post
from masto_bridges.logger import init_logger
2022-11-08 06:13:05 +00:00
from time import sleep
2022-11-08 03:13:35 +00:00
def post_last_commit(config:Optional[Config]=None):
2022-11-08 06:13:05 +00:00
"""
Should be triggered as a commit hook because it doesn't validate
the last commit hasn't already been posted.
"""
2022-11-08 03:13:35 +00:00
if config is None:
config = Config()
2022-11-08 06:13:05 +00:00
logger = init_logger('post-git', basedir=config.LOGDIR)
2022-11-08 03:13:35 +00:00
repo = Repo(config.GIT_REPO)
last_commit = repo.last_commit
2022-11-08 06:13:05 +00:00
post = Post.from_commit(last_commit)
if post.text.startswith('xpost'):
logger.info('Not xposting an xpost')
return
bot = Bot(config=config)
bot.post(post.format_masto())
def masto_bridgebot(config:Optional[Config]=None):
2022-11-08 06:13:05 +00:00
if config is None:
config = Config()
bot = Bot(config=config)
try:
bot.init_stream()
while True:
sleep(1)
if bot.caldav:
# poll for new events
bot.poll_caldav()
# pdb.set_trace()
# print(events.objects)
bot.logger.debug('taking a breath')
2022-11-08 06:13:05 +00:00
except KeyboardInterrupt:
bot.logger.info('quitting!')