[Feed] init

This commit is contained in:
tmshv committed 2017-04-22 01:33:05 +03:00
1 parent 5da1572589
commit 07b03154da
7 files changed
+108

No files matched your search

+13
View File
@@ -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]
+37
View File
@@ -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()
+5
View File
@@ -0,0 +1,5 @@
from server import app
from settings import host
if __name__ == '__main__':
app.run(host=host)
+14
View File
@@ -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
+7
View File
@@ -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')