formatting changes

This commit is contained in:
aj 2019-05-16 16:29:40 +01:00
parent a56ec131de
commit a5d07659eb
6 changed files with 25 additions and 21 deletions

2
.gitignore vendored
View File

@ -3,6 +3,8 @@
*.py[cod] *.py[cod]
*$py.class *$py.class
.idea
# C extensions # C extensions
*.so *.so

View File

@ -1,3 +1,3 @@
Flask==1.0.2 Flask
requests==2.20 requests
google.cloud.firestore==0.31.0 google-cloud.firestore

View File

@ -1,7 +1,4 @@
from flask import Blueprint, render_template, abort from flask import Blueprint, render_template
from jinja2 import TemplateNotFound
from google.cloud import firestore
from .db import getTagDicts, getPopulatedTagDict, getPopulatedTagDicts from .db import getTagDicts, getPopulatedTagDict, getPopulatedTagDicts
@ -9,7 +6,7 @@ staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/'
urlprefix = 'art' urlprefix = 'art'
art_print = Blueprint('art', __name__, template_folder='templates') art_print = Blueprint('art', __name__, template_folder='templates')
#db = firestore.Client()
@art_print.route('/') @art_print.route('/')
def root(): def root():
@ -17,14 +14,14 @@ def root():
#print(tags) #print(tags)
return render_template('art/index.html', tags = tags, staticroot = staticbucketurl, urlprefix = urlprefix) return render_template('art/index.html', tags = tags, staticroot = staticbucketurl, urlprefix = urlprefix)
@art_print.route('/<tag>') @art_print.route('/<tag>')
def tag_view(tag): def tag_view(tag):
tags = getPopulatedTagDict(tag) tags = getPopulatedTagDict(tag)
return render_template('art/all.html', staticroot = staticbucketurl, tags = [tags]) return render_template('art/all.html', staticroot = staticbucketurl, tags = [tags])
@art_print.route('/all') @art_print.route('/all')
def all(): def all():
sections = getPopulatedTagDicts() sections = getPopulatedTagDicts()
return render_template('art/all.html', staticroot = staticbucketurl, tags=sections) return render_template('art/all.html', staticroot = staticbucketurl, tags=sections)

View File

@ -4,6 +4,7 @@ staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/'
fs = firestore.Client() fs = firestore.Client()
def getTagDicts(): def getTagDicts():
art_tags_collection = fs.collection(u'art_tags') art_tags_collection = fs.collection(u'art_tags')
@ -20,6 +21,7 @@ def getTagDicts():
return sorted(dicts, key=lambda k: k['index']) return sorted(dicts, key=lambda k: k['index'])
def getPopulatedTagDict(name): def getPopulatedTagDict(name):
name_doc = fs.document(u'art_tags/{}'.format(name)) name_doc = fs.document(u'art_tags/{}'.format(name))
@ -34,6 +36,7 @@ def getPopulatedTagDict(name):
return tag_dicts return tag_dicts
def getPopulatedTagDicts(): def getPopulatedTagDicts():
tag_dicts = getTagDicts() tag_dicts = getTagDicts()

View File

@ -1,5 +1,4 @@
from flask import Blueprint, render_template, abort from flask import Blueprint, render_template
from jinja2 import TemplateNotFound
import requests import requests
from google.cloud import firestore from google.cloud import firestore
@ -17,15 +16,15 @@ def root():
fmkey = fs.document('key/fm').get().to_dict()['clientid'] fmkey = fs.document('key/fm').get().to_dict()['clientid']
params = { params = {
'method':'user.gettopalbums', 'method': 'user.gettopalbums',
'user':'sarsoo', 'user': 'sarsoo',
'period':'1month', 'period': '1month',
'limit':'6', 'limit': '6',
'api_key':fmkey, 'api_key': fmkey,
'format':'json' 'format': 'json'
} }
req = requests.get(fm_url, params = params) req = requests.get(fm_url, params=params)
albums = req.json()['topalbums']['album'] albums = req.json()['topalbums']['album']
@ -33,4 +32,4 @@ def root():
for image in album['image']: for image in album['image']:
image['text'] = image['#text'] image['text'] = image['#text']
return render_template('music/index.html', albums = albums) return render_template('music/index.html', albums=albums)

View File

@ -8,13 +8,14 @@ from .music import music_print
# Project ID is determined by the GCLOUD_PROJECT environment variable # Project ID is determined by the GCLOUD_PROJECT environment variable
db = firestore.Client() db = firestore.Client()
app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), '..', 'static'), template_folder = "templates") app = Flask(__name__, static_folder=os.path.join(os.path.dirname(__file__), '..', 'static'), template_folder="templates")
app.register_blueprint(art_print, url_prefix='/art') app.register_blueprint(art_print, url_prefix='/art')
app.register_blueprint(music_print, url_prefix='/music') app.register_blueprint(music_print, url_prefix='/music')
staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/' staticbucketurl = 'https://storage.googleapis.com/sarsooxyzstatic/'
@app.route('/') @app.route('/')
def main(): def main():
@ -32,10 +33,12 @@ def main():
return render_template('index.html', staticroot = staticbucketurl, splash = splashtext, art=art) return render_template('index.html', staticroot = staticbucketurl, splash = splashtext, art=art)
@app.route('/dev') @app.route('/dev')
def dev(): def dev():
return render_template('dev.html') return render_template('dev.html')
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True) app.run(host='127.0.0.1', port=8080, debug=True)
# [END gae_python37_app] # [END gae_python37_app]