Compare commits
No commits in common. "6be934e374e5a05e886c21e6c4591e75c1633818" and "d19406d3b450557f0378fcac8f73666e516f505a" have entirely different histories.
6be934e374
...
d19406d3b4
@ -1,11 +1,6 @@
|
|||||||
from typing import Generator, Type, Dict
|
from typing import Generator, Type, Dict
|
||||||
import os.path
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import requests
|
from ..utils import config, error
|
||||||
from ics import Calendar, Event
|
|
||||||
|
|
||||||
from ..utils import config, error, prompt, ICS_FILE
|
|
||||||
from ..feeds import *
|
from ..feeds import *
|
||||||
|
|
||||||
|
|
||||||
@ -41,36 +36,6 @@ class Routine:
|
|||||||
except (TypeError, error.InvalidCredential):
|
except (TypeError, error.InvalidCredential):
|
||||||
raise error.InvalidCredential(f"Invalid credentials for {feed.__name__}.")
|
raise error.InvalidCredential(f"Invalid credentials for {feed.__name__}.")
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_ics(use_cached: bool = False) -> Calendar:
|
|
||||||
if use_cached and ICS_FILE.exists():
|
|
||||||
with ICS_FILE.open("r") as f:
|
|
||||||
return Calendar(f.read())
|
|
||||||
|
|
||||||
ics_url = config.get_field("ics_url")
|
|
||||||
if not len(ics_url):
|
|
||||||
ics_url = prompt.for_string("url or path to the ICS file")
|
|
||||||
config.set_field("ics_url", ics_url)
|
|
||||||
|
|
||||||
origin_path = Path(ics_url)
|
|
||||||
|
|
||||||
if origin_path.is_file():
|
|
||||||
with origin_path.open("rb") as f:
|
|
||||||
with ICS_FILE.open("wb") as t:
|
|
||||||
t.write(f.read())
|
|
||||||
else:
|
|
||||||
r = requests.get(ics_url)
|
|
||||||
with ICS_FILE.open("wb") as t:
|
|
||||||
t.write(r.content)
|
|
||||||
|
|
||||||
with ICS_FILE.open("r") as f:
|
|
||||||
return Calendar(f.read())
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_event_string(event: Event) -> str:
|
|
||||||
return f""
|
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
pass
|
pass
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
from . import Routine
|
from . import Routine
|
||||||
from ..feeds import Feed, TwitterFeed
|
from ..feeds import Feed
|
||||||
from ..utils import date
|
|
||||||
|
|
||||||
from ics import Calendar
|
|
||||||
|
|
||||||
|
|
||||||
class Development(Routine):
|
class Development(Routine):
|
||||||
def run(self):
|
def run(self):
|
||||||
calendar = self.get_ics()
|
for feed_class in self.iter_feeds():
|
||||||
|
feed: Feed = self.init_feed(feed_class)
|
||||||
|
|
||||||
for event in calendar.events:
|
feed.post(message="This worked second try!")
|
||||||
print(event.name, date.event_formatting_values(event, "de"))
|
|
||||||
break
|
|
||||||
|
|
||||||
event_description = f"""
|
|
||||||
Wir treffen uns {event.begin.humanize(locale="de")} zum {event.name}."""
|
|
||||||
print(event_description.strip())
|
|
||||||
print()
|
|
||||||
|
@ -1,23 +1,12 @@
|
|||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import platformdirs
|
import platformdirs
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
PROGRAM_NAME: str = "publish-meetups"
|
PROGRAM_NAME: str = "publish-meetups"
|
||||||
PROGRAM_DATA_DIR: Path = platformdirs.user_config_path(appname=PROGRAM_NAME)
|
PROGRAM_DATA_DIR: str = platformdirs.user_config_path(appname=PROGRAM_NAME)
|
||||||
PROGRAM_DATA_DIR.mkdir(parents=True, exist_ok=True)
|
PROGRAM_DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
ICS_FILE = Path(PROGRAM_DATA_DIR / "meetup.ics")
|
|
||||||
|
|
||||||
|
__all__ = ["prompt", "PROGRAM_DATA_DIR", "PROGRAM_NAME", "errors", "config"]
|
||||||
__all__ = [
|
|
||||||
"prompt",
|
|
||||||
"PROGRAM_DATA_DIR",
|
|
||||||
"PROGRAM_NAME",
|
|
||||||
"errors",
|
|
||||||
"config",
|
|
||||||
"ICS_FILE",
|
|
||||||
"date",
|
|
||||||
]
|
|
||||||
|
@ -11,9 +11,6 @@ _config: dict = {
|
|||||||
"mastodon",
|
"mastodon",
|
||||||
"twitter",
|
"twitter",
|
||||||
],
|
],
|
||||||
"weekday_translations": {},
|
|
||||||
"months_translations": {},
|
|
||||||
"ics_url": "",
|
|
||||||
"mastodon": {},
|
"mastodon": {},
|
||||||
"twitter": {},
|
"twitter": {},
|
||||||
"lemmy": {},
|
"lemmy": {},
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
from datetime import datetime
|
|
||||||
from ics import Calendar, Event
|
|
||||||
|
|
||||||
from . import config
|
|
||||||
|
|
||||||
|
|
||||||
def to_date_string(date_time: datetime) -> str:
|
|
||||||
date_format = config.get_field("date_format", "%Y-%m-%d %H:%M:%S")
|
|
||||||
|
|
||||||
weekday_translations = config.get_field("weekday_translations", {})
|
|
||||||
months_translations = config.get_field("months_translations", {})
|
|
||||||
|
|
||||||
parsed = date_time.strftime(date_format)
|
|
||||||
|
|
||||||
for key, value in weekday_translations.items():
|
|
||||||
parsed = parsed.replace(key, value)
|
|
||||||
|
|
||||||
for key, value in months_translations.items():
|
|
||||||
parsed = parsed.replace(key, value)
|
|
||||||
|
|
||||||
return parsed.strip()
|
|
||||||
|
|
||||||
|
|
||||||
def to_time_string(date_time: datetime) -> str:
|
|
||||||
time_format = config.get_field("time_format", "%H:%M")
|
|
||||||
time_format_full_hour = config.get_field("time_format_full_hour", time_format)
|
|
||||||
|
|
||||||
parsed = date_time.strftime(time_format)
|
|
||||||
if int(date_time.minute) == 0:
|
|
||||||
parsed = date_time.strftime(time_format_full_hour)
|
|
||||||
|
|
||||||
return parsed.strip()
|
|
||||||
|
|
||||||
|
|
||||||
def event_formatting_values(event: Event, locale="en") -> dict:
|
|
||||||
return {
|
|
||||||
"time": to_time_string(event.begin),
|
|
||||||
"date": to_date_string(event.begin),
|
|
||||||
"date_humanized": event.begin.humanize(locale=locale),
|
|
||||||
}
|
|
@ -37,8 +37,6 @@ dependencies = [
|
|||||||
"twikit~=1.1.12",
|
"twikit~=1.1.12",
|
||||||
"toml~=0.10.2",
|
"toml~=0.10.2",
|
||||||
"platformdirs~=3.2.0",
|
"platformdirs~=3.2.0",
|
||||||
"ics~=0.7.2",
|
|
||||||
"requests~=2.31.0"
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
Loading…
Reference in New Issue
Block a user