Example docker configuration and /feeds path.

This commit is contained in:
Benjamin Bouvier 2017-12-30 18:52:02 +01:00
parent 4a5ea453c3
commit 9c3640d25f
4 changed files with 60 additions and 11 deletions

11
Dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM python:3-slim
MAINTAINER Benjamin Bouvier <public@benj.me>
RUN mkdir /app
COPY . /app
RUN cd /app && \
apt update && \
apt install -y --force-yes libpq-dev build-essential && \
pip install -r requirements.txt
CMD ["python", "/app/main.py"]

12
docker-compose.yml Normal file
View File

@ -0,0 +1,12 @@
version: "2"
services:
postgres:
image: postgres
volumes:
- ./data/:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=mysecretpassword
2rss:
build: .
volumes:
- ./settings.ini:/app/settings.ini

47
main.py
View File

@ -53,14 +53,31 @@ else:
raise Exception('unhandled db adapter: {}'.format(db_adapter)) raise Exception('unhandled db adapter: {}'.format(db_adapter))
db.generate_mapping(create_tables=True) db.generate_mapping(create_tables=True)
orm.set_sql_debug(True)
def does_slug_exist(slug): def does_slug_exist(slug):
with orm.db_session: with orm.db_session:
return len(orm.select(f for f in Feed if f.slug == slug)[:1]) return len(orm.select(f for f in Feed if f.slug == slug)[:1])
@app.route('/feeds', methods=['POST'])
@app.route('/feeds', methods=['GET', 'POST'])
@orm.db_session
def add_feed(): def add_feed():
if request.method == 'GET':
feeds = orm.select(f for f in Feed if f.password is '')
links = []
for f in feeds:
link = '<ul><a href={}{}>{}</a></ul>'.format(site_url, f.slug, f.title)
links.append(link)
return """
<body>
<li>
{}
</li>
</body>
""".format('\n'.join(links))
data = request.get_json(silent=True) data = request.get_json(silent=True)
if 'slug' not in data: if 'slug' not in data:
@ -76,19 +93,19 @@ def add_feed():
url = site_url + slug url = site_url + slug
with orm.db_session: feed = Feed(slug=slug,
feed = Feed(slug=slug, admin_token=data['admin_token'],
admin_token=data['admin_token'], title=data['title'],
title=data['title'], atom_id=url,
atom_id=url, description=data['description'])
description=data['description'])
if 'login' in data and 'password' in data: if 'login' in data and 'password' in data:
feed.login = data['login'] feed.login = data['login']
feed.password = data['password'] feed.password = data['password']
return "OK" return "OK"
@app.route('/feeds/<slug>', methods=['GET', 'POST']) @app.route('/feeds/<slug>', methods=['GET', 'POST'])
@orm.db_session @orm.db_session
def by_feed_name(slug): def by_feed_name(slug):
@ -139,3 +156,11 @@ def by_feed_name(slug):
fe.updated(date) fe.updated(date)
return gen.atom_str(pretty=True).decode('utf8') return gen.atom_str(pretty=True).decode('utf8')
if __name__ == '__main__':
debug_str = config['general'].get('debug', 'False')
debug = debug_str != 'False' and debug_str != 'false'
orm.set_sql_debug(debug)
app.run(debug=debug, host='0.0.0.0')

View File

@ -1,5 +1,6 @@
[general] [general]
site_url=http://localhost:5000 site_url=http://localhost:5000
debug=true
[db] [db]
adapter=postgres adapter=postgres