This commit is contained in:
www
2020-10-26 20:30:12 +00:00
commit 58be5c779a
14 changed files with 673 additions and 0 deletions

38
fet2020api/__init__.py Normal file
View File

@@ -0,0 +1,38 @@
import requests
from .djangoapi import django_crud_api
class fet2020postapi(django_crud_api):
def __init__(self,endpoint="http://localhost:8106/api/posts/"):
super().__init__(endpoint=endpoint)
def read_post(self, slug=None,legacy_id=None):
return self.find_one({'slug':slug,'legacy_id':legacy_id})
def update_or_write_by_legacy_id(self,d):
if not 'legacy_id' in d:
raise AttributeError('legacy_id muss angegeben werden')
p=self.read_post(legacy_id=d['legacy_id'])
if p is None:
p=self.create(d)
else:
p=self.update(p['slug'], d)
return p
def push(self,d):
return self.update_or_write_by_legacy_id(d)
class fet2020memberapi(django_crud_api):
def __init__(self, endpoint= "http://localhost:8103/api/members/"):
super().__init__(endpoint=endpoint)
def read_post(self, slug=None,legacy_id=None):
return self.find_one({'nickname':slug,'legacy_id':legacy_id})
def update_or_write_by_legacy_id(self,d):
if not 'legacy_id' in d:
raise AttributeError('legacy_id muss angegeben werden')
p=self.read_post(legacy_id=d['legacy_id'])
if p is None:
p=self.create(d)
else:
p=self.update(p['slug'], d)
return p