Browse Source

Upadate service

pull/7/head
Marian Steinbach 2 years ago
parent
commit
1d6975a5f3
  1. 2
      .gitignore
  2. 1
      service/.dockerignore
  3. 6
      service/Dockerfile
  4. 6
      service/Makefile
  5. 5
      service/api/events.py
  6. 16
      service/api/main.py
  7. 2
      service/requirements.txt

2
.gitignore vendored

@ -0,0 +1,2 @@
.DS_Store
service/secrets.env

1
service/.dockerignore

@ -0,0 +1 @@
/venv

6
service/Dockerfile

@ -1,4 +1,8 @@
FROM python:3.6-alpine3.6
FROM python:3.6-alpine3.8
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
ENV PYTHONUNBUFFERED yes
WORKDIR /app

6
service/Makefile

@ -1,4 +1,10 @@
build:
docker build -t quay.io/netzbegruneung/schaufenster-service .
run:
docker run -p 5000:5000 --rm quay.io/netzbegruneung/schaufenster-service
serve:
gunicorn --reload -b 0.0.0.0:5000 api.main:app

5
service/api/events.py

@ -4,6 +4,7 @@ import requests
import icalendar
from datetime import datetime
from datetime import date
from datetime import timedelta
class Client(object):
@ -12,7 +13,7 @@ class Client(object):
self.url = url
self.charset = charset
self.events = []
self.timeout = 20
self.timeout = 60
self.__load()
def __load(self):
@ -50,7 +51,7 @@ class Client(object):
"""
Returns the next num events from the calendar
"""
now = datetime.utcnow()
now = datetime.utcnow() + timedelta(hours=5)
out = []
for event in self.events:
end = event["end"]

16
service/api/main.py

@ -11,6 +11,21 @@ import logging
import requests
class IndexResource(object):
def __init__(self):
self.logger = logging.getLogger('api.' + __name__)
def on_get(self, req, resp):
resp.media = {
"message": "Hallo! Hier läuft der Schaufenster-Service",
"url": "https://github.com/netzbegruenung/schaufenster",
"endpoints": [
"/events/",
"/feed/",
"/luftdaten.info/v1/sensor/{sensor_id}/",
],
}
class EventsResource(object):
def __init__(self):
@ -75,3 +90,4 @@ app.resp_options.media_handlers = handlers
app.add_route('/events/', EventsResource())
app.add_route('/feed/', FeedResource())
app.add_route('/luftdaten.info/v1/sensor/{sensor_id}/', ParticleSensorResource())
app.add_route('/', IndexResource())

2
service/requirements.txt

@ -14,6 +14,6 @@ pytest==3.4.0
python-dateutil==2.6.1
python-mimeparse==1.6.0
pytz==2017.3
requests==2.18.4
requests==2.20.1
six==1.11.0
urllib3==1.22

Loading…
Cancel
Save