You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB
Python

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

"""helper functions (is it really usefull?)
TODO: maybe all these calculations are to be put in the db storage
"""
from unidecode import unidecode # to remove accents in house and prince names in the urls
def make_timeitem_from_filename(filename):
"""
"anj_isa_i_1441_08_05a" -> "1441_08_05a"
"""
trs_fname = filename.split('_')
return "_".join(trs_fname[3:])
def normalize_trigrams(trigram):
"""normalizes names, usefull for the uris routes
sample: Alençon -> Alencon
Orléans -> Orleans
"""
return {unidecode(value):key for key, value in trigram.items()}
#from flask import abort
#
#def find_one_or_404(collection, **kwargs):
# """Find a single document or raise a 404.
#
# This is like :meth:`~pymongo.collection.Collection.find_one`, but
# rather than returning ``None``, cause a 404 Not Found HTTP status
# on the request.
#
# .. code-block:: python
#
# usercollection = mydb['usercollection']
#
# @app.route("/user/<username>")
# def user_profile(username):
# userfound = find_one_or_404(usercollection, {"_id": username})
# return render_template("user.html",
# user=userfound)
# """
# found = collection.find_one(**kwargs)
# if found is None:
# abort(404)
# return found