/
rfeed.py
87 lines (69 loc) · 2.85 KB
/
rfeed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import flask,requests
from datetime import datetime, date
from flask import request , jsonify
from flask import Response
from feedgen.feed import FeedGenerator
app = flask.Flask(__name__)
@app.route('/summary', methods=['GET'])
def getsummary():
req= requests.get('http://localhost/article',json={"count" : 10} , auth=('admin@email.com', 'adminpassword'))
value = req.json()
fg = FeedGenerator()
fg.title('Summary of 10 newest articles')
fg.link( href='http://localhost/feed/summary' )
fg.subtitle('This is a cool feed!')
fg.language('en')
for x in value:
fe = fg.add_entry()
fe.title(x.get('articles_title',''))
fe.category(term= "Author "+ x.get('articles_users_author',''))
fe.category(term= "Date "+ x.get('articles_modified', ''))
fe.link(href="http://localhost"+x.get('articles_url',''))
fg.rss_file('summary_10.xml')
return "RSS FILE CREATED summary_10.xml", 200
@app.route('/summary/content', methods=['GET'])
def getcontent():
req= requests.get('http://localhost/article/content',json={"count" : 10} , auth=('admin@email.com', 'adminpassword'))
value = req.json()
fg = FeedGenerator()
fg.title('A full feed')
fg.link( href='http://localhost/feed/summary/content' )
fg.subtitle('This is a cool feed!')
fg.language('en')
for x in value:
fe = fg.add_entry()
fe.content(x.get('articles_content',''))
if x.get('articles_tags','') != 'null':
for v in x.get('articles_tags',''):
fe.category(term= 'Tag: '+ v)
else:
fe.category(term= 'Tag: None')
if type(x.get('articles_comments','')) == type(None):
count = '0'
else:
count = str(len(x.get('articles_comments','')))
fe.category(term = 'Comment Count: '+ count)
fg.rss_file('content.xml')
return "YOUR CONTENT WAS CREATED content.xml", 200
@app.route('/summary/comments', methods=['GET'])
def getcomments():
req= requests.get('http://localhost/article',json={"count" : 10} , auth=('admin@email.com', 'adminpassword'))
value = req.json()
fg = FeedGenerator()
fg.title('A full feed')
fg.link( href='http://localhost/feed/summary/comments' )
fg.subtitle('This is a cool feed!')
fg.language('en')
for x in value:
split = x.get('articles_url','').split('/')
reqcomment=requests.get('http://localhost/comment/get/'+split[2],json={"count" : 30} , auth=('admin@email.com', 'adminpassword'))
fe = fg.add_entry()
fe.content(x.get('articles_url', ''))
if reqcomment.status_code == 200:
for v in reqcomment.json():
fe.category(term= v)
else:
fe.category(term="None")
fg.rss_file('comments.xml')
return "YOUR COMMENTS WAS CREATED comments.xml", 200
app.run()