-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
70 lines (52 loc) · 1.71 KB
/
app.py
File metadata and controls
70 lines (52 loc) · 1.71 KB
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
import flask
import twitter
import os
import sys
import yaml
from lib import cfg
from service.card import app as card_app
from service.template import app as template_app
from service.resource import app as resource_app
app = flask.Flask(
'stuff'
)
app.register_blueprint(resource_app, url_prefix='/resource')
app.register_blueprint(card_app, url_prefix='/card')
app.register_blueprint(template_app, url_prefix='/template')
@app.route("/")
def index():
return app.send_static_file('html/base.html')
@app.route('/timeline/<name>')
def timeline(name):
x = {'timeline': app.twitter.get_timeline(name)}
return flask.jsonify(**x)
@app.route('/profile/<name>')
def profile(name):
x = {'profile': app.twitter.get_profile(name)}
return flask.jsonify(**x)
@app.route('/static/resource/<path:filename>')
def serve_resources(filename):
return flask.send_from_directory(
cfg.config['storage']['resource'],
filename
)
if __name__ == '__main__':
config_path = sys.argv[1]
config_file = ''
with open(config_path, 'r') as f:
config_file = f.read()
cfg.initialize(yaml.load(config_file))
# ensure storage locations exist
if not os.path.isdir(cfg.config['storage']['card']):
os.makedirs(cfg.config['storage']['card'])
if not os.path.isdir(cfg.config['storage']['template']):
os.makedirs(cfg.config['storage']['template'])
if not os.path.isdir(cfg.config['storage']['resource']):
os.makedirs(cfg.config['storage']['resource'])
app.twitter = twitter.Twitter()
app.twitter.acquire_token(
cfg.config['twitter']['key'],
cfg.config['twitter']['secret']
)
app.debug = True
app.run(port=cfg.config['app']['port'])