[Feed] init
This commit is contained in:
1 parent
5da1572589
commit
07b03154da
7 files changed
+108
No files matched your search
@@ -0,0 +1,27 @@
|
|||||||
|
FROM alpine:3.5
|
||||||
|
|
||||||
|
RUN apk add --no-cache python3 && \
|
||||||
|
apk add --no-cache py3-lxml && \
|
||||||
|
python3 -m ensurepip && \
|
||||||
|
rm -r /usr/lib/python*/ensurepip && \
|
||||||
|
pip3 install --upgrade pip setuptools && \
|
||||||
|
rm -r /root/.cache
|
||||||
|
|
||||||
|
LABEL maintainer "Roman Timashev <roman@tmshv.ru>"
|
||||||
|
|
||||||
|
ENV INSTALL_PATH /app
|
||||||
|
RUN mkdir -p $INSTALL_PATH
|
||||||
|
WORKDIR /$INSTALL_PATH
|
||||||
|
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip3 install -r requirements.txt
|
||||||
|
|
||||||
|
COPY app ./app
|
||||||
|
|
||||||
|
ENV DB_URI "mongodb://localhost:27017"
|
||||||
|
ENV DB_USER ""
|
||||||
|
ENV DB_PASSWORD ""
|
||||||
|
ENV DB_NAME "hudozka"
|
||||||
|
|
||||||
|
EXPOSE 5000
|
||||||
|
CMD python3 app/main.py
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
from pymongo import MongoClient
|
||||||
|
from settings import db_uri, db_name, db_user, db_password
|
||||||
|
|
||||||
|
db = MongoClient(db_uri)[db_name]
|
||||||
|
if db_user and db_password:
|
||||||
|
auth_status = db.authenticate(db_user, db_password)
|
||||||
|
if not auth_status:
|
||||||
|
print('Failed to authenticate user')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def collection(name):
|
||||||
|
return db[name]
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import html
|
||||||
|
|
||||||
|
from feedgen.feed import FeedGenerator
|
||||||
|
|
||||||
|
from db import collection
|
||||||
|
|
||||||
|
|
||||||
|
def get_feed():
|
||||||
|
events = list(collection('events').find({}))
|
||||||
|
news = list(collection('timeline').find({'type': 'post'}))
|
||||||
|
|
||||||
|
articles = events + news
|
||||||
|
|
||||||
|
fg = FeedGenerator()
|
||||||
|
fg.id('1')
|
||||||
|
fg.title('Шлиссельбургская ДХШ')
|
||||||
|
# fg.author({'name': 'John Doe', 'email': 'john@example.de'})
|
||||||
|
fg.link(href='https://art.shlisselburg.org', rel='alternate')
|
||||||
|
# fg.logo('http://ex.com/logo.jpg')
|
||||||
|
# fg.subtitle('События ')
|
||||||
|
fg.link(href='https://art.shlisselburg.org/feed', rel='self')
|
||||||
|
fg.language('en')
|
||||||
|
|
||||||
|
for article in articles:
|
||||||
|
content = html.unescape(article['post'])
|
||||||
|
article_id = article['id']
|
||||||
|
url = 'https://art.shlisselburg.org/article/{id}'.format(id=article_id)
|
||||||
|
|
||||||
|
fe = fg.add_entry()
|
||||||
|
fe.id(article_id)
|
||||||
|
fe.title(article['title'])
|
||||||
|
fe.content(content, None, 'CDATA')
|
||||||
|
fe.link({'href': url})
|
||||||
|
|
||||||
|
# return articles
|
||||||
|
return fg.atom_str(pretty=True)
|
||||||
|
# return fg.atom_str()
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from server import app
|
||||||
|
from settings import host
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(host=host)
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from flask import Flask
|
||||||
|
|
||||||
|
from feed import get_feed
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def root():
|
||||||
|
feed = get_feed()
|
||||||
|
if not feed:
|
||||||
|
return '', 404
|
||||||
|
|
||||||
|
return feed
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
db_uri = os.getenv('DB_URI', 'mongodb://localhost:27017')
|
||||||
|
db_name = os.getenv('DB_NAME', 'hudozka')
|
||||||
|
db_user = os.getenv('DB_USER', None)
|
||||||
|
db_password = os.getenv('DB_PASSWORD', None)
|
||||||
|
host = os.getenv('APP_HOST', '0.0.0.0')
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
pymongo==3.4.0
|
||||||
|
Flask==0.12
|
||||||
|
redis==2.10.5
|
||||||
|
PyYAML==3.12
|
||||||
|
feedgen==0.5.1
|
||||||
Reference in new issue
Block a user