forked from andskli/repostatus-gh-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
42 lines (34 loc) · 1.09 KB
/
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
36
37
38
39
40
41
42
from flask import Flask, render_template
from ddbcache import DDBCache
from github import Github
app = Flask(__name__)
ddb = DDBCache(table_name='repostatus_cache')
gh = Github()
@app.route("/")
def index():
return render_template('index.html')
@app.route("/repo/<path:repo_slug>")
def repo(repo_slug):
r = {
'repo_slug': repo_slug,
'data': {}
}
cached = ddb.get(repo_slug)
if cached:
app.logger.debug("Found repo in DDB cache")
r['data'] = cached
else:
app.logger.debug("Couldn't find repo in cache")
try:
repo = gh.get_repo(r['repo_slug'])
r['data']['stargazers_count'] = repo.stargazers_count
r['data']['watchers_count'] = repo.watchers_count
r['data']['open_issues_count'] = repo.open_issues_count
print("REPO DATA: ", r['data'])
print("PUTTING: ", r['repo_slug'], r['data'])
ddb.put(r['repo_slug'], r['data'])
except Exception as e:
print(e)
return render_template('repo.html', repo=r)
if __name__ == '__main__':
app.run()