cleaned up code with flake8 and black

This commit is contained in:
crunk 2020-12-21 18:58:46 +01:00
parent 456c674326
commit 230f242af5
2 changed files with 28 additions and 7 deletions

View File

@ -17,12 +17,15 @@ def getpublications():
csv_as_dict = csv.DictReader(libcsv) csv_as_dict = csv.DictReader(libcsv)
publications = {} publications = {}
for row in csv_as_dict: for row in csv_as_dict:
pubinfo = {"Title" : row["Publication"], pubinfo = {
"Title": row["Publication"],
"Author": row["Author"], "Author": row["Author"],
"Type" : row["Type"]} "Type": row["Type"],
}
publications[row["Id"]] = pubinfo publications[row["Id"]] = pubinfo
return publications return publications
def gettypes(): def gettypes():
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r") libcsv = open(os.path.join(script_dir, "varlib.csv"), "r")
with libcsv: with libcsv:
@ -32,9 +35,20 @@ def gettypes():
lowertype = row["Type"].lower() lowertype = row["Type"].lower()
if lowertype not in listoftypes: if lowertype not in listoftypes:
listoftypes.append(lowertype) listoftypes.append(lowertype)
#listoftypes = [t.title() for t in listoftypes]
return listoftypes return listoftypes
def getyears():
libcsv = open(os.path.join(script_dir, "varlib.csv"), "r")
with libcsv:
csv_as_dict = csv.DictReader(libcsv)
listofyears = []
for row in csv_as_dict:
if row["Year"] not in listofyears:
listofyears.append(row["Year"])
return listofyears
# test = getpublications() # test = getpublications()
# for ids, pubinfo in test.items(): # for ids, pubinfo in test.items():
# print(pubinfo["Title"]) # print(pubinfo["Title"])

View File

@ -4,7 +4,7 @@
import flask import flask
from flask import render_template from flask import render_template
from csvparser.csvparser import getpublications, gettypes from csvparser.csvparser import getpublications, gettypes, getyears
APP = flask.Flask(__name__, static_folder="static") APP = flask.Flask(__name__, static_folder="static")
@ -14,15 +14,22 @@ def index():
"""Main route""" """Main route"""
# parse csv, render template with a few elements from the csv # parse csv, render template with a few elements from the csv
pubtypes = gettypes() pubtypes = gettypes()
pubyears = getyears()
publicatons = getpublications() publicatons = getpublications()
return render_template("index.html", publications=publicatons, pubtypes=pubtypes) template = render_template(
"index.html",
publications=publicatons,
pubtypes=pubtypes,
pubyears=pubyears
)
return template
@APP.route("/<publicationID>") @APP.route("/<publicationID>")
def show_book(publicationID): def show_book(publicationID):
"""route for a publication""" """route for a publication"""
# parse csv, render template with full list. # parse csv, render template with full list.
return render_template("publication.html", publication=publication) return render_template("publication.html")
@APP.route("/<publication>") @APP.route("/<publication>")