-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
executable file
·35 lines (26 loc) · 932 Bytes
/
app.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
#!/usr/bin/env python
"""A web interface on a parser which generates a digraph depicting
interconnections between subreddits, based on links in the sidebar
descriptions."""
import logging
from math import log
from flask import Flask, jsonify, render_template, request
from RedditParser import RedditParser
app = Flask(__name__)
_log = logging.getLogger(__name__)
parser = RedditParser()
@app.route('/<subs>/')
def show_graph(subs):
subreddits = subs.split('+')
return render_template('graphview.html', subreddits=subreddits)
@app.route('/_get_subs')
def get_subs():
parent = request.args.get('parent', 'reddit.com')
_log.info("Requesting information for /r/" + parent)
subreddits, subscribers = parser.get_info(parent)
size = log(subscribers)
return jsonify(subreddits=list(subreddits), size=size)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
_log.info("Starting app.")
app.run(debug=True)