diff --git a/.gitignore b/.gitignore index 6b9f39e..fe7241d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ json/* __pycache__/ +*.swp diff --git a/README.md b/README.md new file mode 100644 index 0000000..e984eb1 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Recommendation Engine Example + +## Install dependencies and run: + + python3 -m venv ./venv --system-site-packages + ./venv/bin/pip install -r requirements.txt + + ./venv/bin/python server.py diff --git a/etc/systemd/system/dd-re.service b/etc/systemd/system/dd-re.service new file mode 100644 index 0000000..3cc90c0 --- /dev/null +++ b/etc/systemd/system/dd-re.service @@ -0,0 +1,13 @@ +[Unit] +Description=dd-re + +[Service] +Type=simple +Restart=always +User=dd +Group=dd +WorkingDirectory=/srv/dd/re +ExecStart=/srv/dd/re/server.py + +[Install] +WantedBy=multi-user.target diff --git a/recommendation_engine.py b/recommendation_engine.py index cbfdd96..70f616e 100644 --- a/recommendation_engine.py +++ b/recommendation_engine.py @@ -9,6 +9,8 @@ import random import ox +from utils import run_async + class Engine: def __init__(self, path): @@ -111,6 +113,10 @@ class Engine: with open(os.path.join(self.path, 'playlists.json'), 'w') as f: f.write(json.dumps(self.playlists, indent=4, sort_keys=True)) + @run_async + def update_async(self): + self.update() + class Pandora: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..64c5e3f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +tornado +ox diff --git a/server.py b/server.py old mode 100755 new mode 100644 index d084f91..02f4276 --- a/server.py +++ b/server.py @@ -94,12 +94,7 @@ def main(prefix='json/'): app.listen(settings['port'], settings['address']) main = IOLoop.instance() - @run_async - def update(): - engine.update() - - update_cb = PeriodicCallback(update, 60000) - + update_cb = PeriodicCallback(engine.update_async, 15*60*1000) #main.spawn_callback(update, engine) #fixme run periodically