Add push notifications for forgotten departures #26
|
@ -19,7 +19,7 @@ class Config:
|
|||
configfile = findConfigFile()
|
||||
|
||||
if configfile:
|
||||
self.config = ConfigParser()
|
||||
self.config = ConfigParser(strict=False)
|
||||
self.config.read(configfile)
|
||||
else:
|
||||
raise Exception("No config file found")
|
||||
|
|
|
@ -180,12 +180,7 @@ def post_pushsub():
|
|||
except ValueError as e:
|
||||
return 'Error: JSON decode error:\n' + str(e), 400
|
||||
|
||||
name = slugify(data['name'])
|
||||
data['name'] = name
|
||||
print(json.dumps(data, indent=SPACES))
|
||||
|
||||
Entry = Query()
|
||||
pushsubs.upsert(data, Entry.name == name)
|
||||
notifier.subscribe_user(data)
|
||||
|
||||
return 'OK', 201
|
||||
|
||||
|
@ -211,6 +206,6 @@ def testpush(name):
|
|||
error = notifier.notify_user(arrivals[0])
|
||||
|
||||
if error:
|
||||
return 'Error: ' + error, 201
|
||||
return 'Error: ' + error, 404
|
||||
|
||||
return 'OK', 201
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
from slugify import slugify
|
||||
from threading import Thread, Event
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
@ -10,6 +11,16 @@ ONE_HOUR_IN_S = 60 * 60
|
|||
|
||||
class Notifier(Thread):
|
||||
|
||||
def subscribe_user(self, data):
|
||||
|
||||
pushsubs = self.db.table('pushsubs')
|
||||
|
||||
name = slugify(data['name'])
|
||||
data['name'] = name
|
||||
|
||||
Entry = Query()
|
||||
pushsubs.upsert(data, Entry.name == name)
|
||||
|
||||
def notify_user(self, arrival):
|
||||
|
||||
pushsubs = self.db.table('pushsubs')
|
||||
|
|
|
@ -250,7 +250,6 @@ function initPush(name) {
|
|||
applicationServerKey: pushServerPublicKey
|
||||
}).then(function(subscription) {
|
||||
console.log("User is subscribed:", subscription);
|
||||
localStorage.setItem('pushsub', subscription);
|
||||
|
||||
fetch('/pushsubscribe', {
|
||||
method: "POST",
|
||||
|
@ -259,6 +258,9 @@ function initPush(name) {
|
|||
name: name,
|
||||
sub: subscription
|
||||
})
|
||||
}).then(function(res) {
|
||||
if (res.ok)
|
||||
localStorage.setItem('pushsub', subscription);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue