added caldav event import
This commit is contained in:
@@ -2,3 +2,7 @@ CARDDAV_URL=
|
||||
CARDDAV_USER=
|
||||
CARDDAV_PASSWORD=
|
||||
CARDDAV_IGNORE_STR=
|
||||
|
||||
CALDAV_URL=
|
||||
CALDAV_USER=
|
||||
CALDAV_PASSWORD=
|
||||
|
||||
@@ -1,19 +1,34 @@
|
||||
blinker==1.9.0
|
||||
caldav==3.2.1
|
||||
certifi==2026.7.22
|
||||
charset-normalizer==3.5.1
|
||||
click==8.4.2
|
||||
dnspython==2.8.0
|
||||
dotenv==0.9.9
|
||||
Flask==3.1.3
|
||||
h11==0.16.0
|
||||
icalendar==7.2.2
|
||||
icalendar-searcher==1.0.6
|
||||
idna==3.18
|
||||
itsdangerous==2.2.0
|
||||
jh2==5.0.13
|
||||
Jinja2==3.1.6
|
||||
logging==0.4.9.6
|
||||
lxml==6.1.1
|
||||
MarkupSafe==3.0.3
|
||||
niquests==3.21.0
|
||||
python-dateutil==2.9.0.post0
|
||||
python-dotenv==1.2.2
|
||||
pytz==2026.3.post1
|
||||
PyYAML==6.0.3
|
||||
qh3==1.9.4
|
||||
recurring-ical-events==3.8.2
|
||||
requests==2.34.2
|
||||
six==1.17.0
|
||||
tzdata==2026.3
|
||||
urllib3==2.7.0
|
||||
urllib3-future==2.24.901
|
||||
vobject==0.9.9
|
||||
wassima==2.1.3
|
||||
Werkzeug==3.1.8
|
||||
x-wr-timezone==2.0.1
|
||||
|
||||
+29
-3
@@ -1,4 +1,4 @@
|
||||
import vobject, requests, logging, sys
|
||||
import vobject, requests, logging, sys, caldav
|
||||
|
||||
from src.person import Person
|
||||
from src.config import *
|
||||
@@ -6,9 +6,17 @@ from src.config import *
|
||||
class CardDAVSyncError(Exception):
|
||||
pass
|
||||
|
||||
class CalDAVSyncError(Exception):
|
||||
pass
|
||||
|
||||
class Addressbook:
|
||||
def __init__(self):
|
||||
self.people = []
|
||||
self.events = []
|
||||
|
||||
self.calendar = caldav.Calendar(client=caldav.DAVClient(url=CALDAV_URL, username=CALDAV_USER, password=CALDAV_PASSWORD), url=CALDAV_URL)
|
||||
|
||||
# init cardDAV
|
||||
logger = logging.getLogger(__name__)
|
||||
try:
|
||||
self.sync_with_carddav()
|
||||
@@ -16,7 +24,16 @@ class Addressbook:
|
||||
logger.exception("Failed initial sync with cardDAV server. Failure is not allowed!")
|
||||
sys.exit(1)
|
||||
logger.info(f"{len(self.people)} Contacts synced from cardDAV server!")
|
||||
|
||||
|
||||
# init calDAV
|
||||
try:
|
||||
self.sync_with_caldav()
|
||||
except Exception:
|
||||
logger.exception("Failed initial sync with calDAV server. Failure is not allowed!")
|
||||
sys.exit(1)
|
||||
logger.info(f"{len(self.events)} Events synced from calDAV server!")
|
||||
|
||||
|
||||
def sync_with_carddav(self):
|
||||
try:
|
||||
resp = requests.get(CARDDAV_URL, auth=(CARDDAV_USER, CARDDAV_PASSWORD))
|
||||
@@ -30,7 +47,16 @@ class Addressbook:
|
||||
self.people = people_cleaned
|
||||
|
||||
except Exception as e:
|
||||
raise CardDAVSyncError(f"Failed to sync with server: {e}")
|
||||
raise CardDAVSyncError(f"Failed to sync with CardDAV server: {e}")
|
||||
|
||||
def sync_with_caldav(self):
|
||||
try:
|
||||
events = self.calendar.events()
|
||||
for event in events:
|
||||
ical = event.icalendar_component
|
||||
self.events = events
|
||||
except Exception as e:
|
||||
raise CalDAVSyncError(f"Failed to sync with CalDAV server: {e}")
|
||||
|
||||
def __str__(self):
|
||||
return "\n".join(str(person) for person in self.people)
|
||||
|
||||
@@ -10,6 +10,9 @@ try:
|
||||
CARDDAV_PASSWORD = os.environ["CARDDAV_PASSWORD"]
|
||||
CARDDAV_IGNORE_STR = os.environ["CARDDAV_IGNORE_STR"]
|
||||
|
||||
CALDAV_URL = os.environ["CALDAV_URL"]
|
||||
CALDAV_USER = os.environ["CALDAV_USER"]
|
||||
CALDAV_PASSWORD = os.environ["CALDAV_PASSWORD"]
|
||||
_logger.info("Config loaded!")
|
||||
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user