socialwatch api endpoints work. That was easier then expected
This commit is contained in:
@@ -29,10 +29,13 @@ class ModuleManager:
|
||||
mod_path = f"{modules_package}.{name}.module"
|
||||
try:
|
||||
mod = importlib.import_module(mod_path)
|
||||
except ModuleNotFoundError:
|
||||
logging.getLogger(__name__).warn(f"Module Folder '{name}' without module found")
|
||||
continue # folder without a module.py -> skip silently, or log a warning
|
||||
|
||||
except ModuleNotFoundError as e:
|
||||
if e.name == mod_path:
|
||||
logging.getLogger(__name__).warning(f"Module Folder '{name}' without module found")
|
||||
else:
|
||||
logging.getLogger(__name__).error(f"Error importing '{mod_path}': {e}")
|
||||
continue
|
||||
|
||||
cls = getattr(mod, "MODULE_CLASS", None)
|
||||
if cls is None:
|
||||
logging.getLogger(__name__).warn(f"Module was detected but no class specified with MODULE_CLASS!")
|
||||
|
||||
@@ -3,12 +3,12 @@ from typing import override
|
||||
from flask import Blueprint, send_from_directory, jsonify, app
|
||||
from base.basemodule import BaseModule
|
||||
|
||||
from src.fetch_job import BGFetchJob
|
||||
from src.score import get_social_scores_dict
|
||||
from src.person import Person
|
||||
from src.addressbook import Addressbook
|
||||
from .src.fetch_job import BGFetchJob
|
||||
from .src.score import get_social_scores_dict
|
||||
from .src.person import Person
|
||||
from .src.addressbook import Addressbook
|
||||
|
||||
from src import config
|
||||
from .src import config
|
||||
|
||||
class SocialWatchModule(BaseModule):
|
||||
def __init__(self, app: app):
|
||||
@@ -38,7 +38,6 @@ class SocialWatchModule(BaseModule):
|
||||
def sync(self):
|
||||
pass
|
||||
|
||||
|
||||
# ROUTES ===
|
||||
|
||||
@override
|
||||
@@ -49,17 +48,17 @@ class SocialWatchModule(BaseModule):
|
||||
)
|
||||
|
||||
# people
|
||||
def api_people():
|
||||
return jsonify([p.as_dict() for p in addrbook.people])
|
||||
def api_people(self):
|
||||
return jsonify([p.as_dict() for p in self.addrbook.people])
|
||||
|
||||
def api_person_by_id(id):
|
||||
for person in addrbook.people:
|
||||
def api_person_by_id(self, id):
|
||||
for person in self.addrbook.people:
|
||||
if person.uid == id:
|
||||
return jsonify(person.as_dict())
|
||||
return jsonify({"error": "not found"}), 404
|
||||
|
||||
def api_photo_by_id(id):
|
||||
for person in addrbook.people:
|
||||
def api_photo_by_id(self, id):
|
||||
for person in self.addrbook.people:
|
||||
if person.uid == id:
|
||||
return jsonify({
|
||||
"photo":person.photo,
|
||||
@@ -68,23 +67,23 @@ class SocialWatchModule(BaseModule):
|
||||
return jsonify({"error": "not found"}), 404
|
||||
|
||||
# events
|
||||
def api_events():
|
||||
return jsonify([e.as_dict() for e in addrbook.events])
|
||||
def api_events(self):
|
||||
return jsonify([e.as_dict() for e in self.addrbook.events])
|
||||
|
||||
def api_event_by_id(id):
|
||||
for event in addrbook.events:
|
||||
def api_event_by_id(self, id):
|
||||
for event in self.addrbook.events:
|
||||
if event.uid == id:
|
||||
return jsonify(event.as_dict())
|
||||
return jsonify({"error": "not found"}), 404
|
||||
|
||||
# parse fails
|
||||
def api_parse_errors():
|
||||
def api_parse_errors(self):
|
||||
return jsonify([{
|
||||
"event_uid":m["event"].uid,
|
||||
"name":str(m["name"])
|
||||
} for m in addrbook.missing_contacts])
|
||||
} for m in self.addrbook.missing_contacts])
|
||||
|
||||
def api_scores():
|
||||
return jsonify(get_social_scores_dict(addrbook))
|
||||
def api_scores(self):
|
||||
return jsonify(get_social_scores_dict(self.addrbook))
|
||||
|
||||
MODULE_CLASS = SocialWatchModule
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import vobject, requests, logging, sys, caldav
|
||||
from datetime import date, datetime
|
||||
|
||||
from src.score import event_date
|
||||
from src.person import Person
|
||||
from src.event import Event
|
||||
from src.config import *
|
||||
from .score import event_date
|
||||
from .person import Person
|
||||
from .event import Event
|
||||
from .config import *
|
||||
|
||||
def normalize_date(dt):
|
||||
return dt.date() if isinstance(dt, datetime) else dt
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import time, logging, threading
|
||||
|
||||
from src import config
|
||||
from src.addressbook import Addressbook
|
||||
from . import config
|
||||
from .addressbook import Addressbook
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import vobject, base64
|
||||
from datetime import date, datetime
|
||||
import uuid
|
||||
|
||||
from src import config
|
||||
from . import config
|
||||
|
||||
class Person:
|
||||
def __init__(self, vcard):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from datetime import date, datetime, timedelta
|
||||
from src.config import *
|
||||
from .config import *
|
||||
|
||||
def get_social_scores_dict(ab: Addressbook):
|
||||
from src.addressbook import Addressbook
|
||||
|
||||
Reference in New Issue
Block a user