Example #1
0
app.config.update(data)

# Make dir
RESULT_FOLDER = path.join(_ROOT, "results")
app.config["RESULT_FOLDER"] = RESULT_FOLDER

app.config["FILE_LIMIT"] = FILE_LIMIT

if not path.exists(RESULT_FOLDER):
    makedirs(RESULT_FOLDER)


# add db, define db class

app.config["DB_PATH"] = path.join(_ROOT, "mapomat.db")
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///%s" % app.config["DB_PATH"]
# Make annoying warning go away
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)

# Determine longest city string for database field length
city_max_length = max([len(key) for key in app.config["city_categories"]])


class KmlInfo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    city = db.Column(db.Unicode(city_max_length))
    legend = db.Column(db.Text)
    color_info = db.Column(db.Text)
    scaling = db.Column(db.Float)
Example #2
0
import os, json
import threading
import logging
import hashlib
from flask import Flask, render_template, request, redirect, url_for, send_from_directory

logging.basicConfig(level=logging.INFO)

app = Flask(__name__)
app.config["UPLOAD_FOLDER"] = "uploads"
app.config["MAX_CONTENT_LENGTH"] = 16 * 1024 * 1024
app.config["DB_PATH"] = "answers.json"

if not os.path.exists(app.config["UPLOAD_FOLDER"]):
    os.makedirs(app.config["UPLOAD_FOLDER"])

if os.path.exists(app.config["DB_PATH"]):
    with open(app.config["DB_PATH"], "r") as f:
        answers = json.load(f)
else:
    answers = {}

lock = threading.RLock()


def save_answers():
    with lock:
        with open(app.config["DB_PATH"], "w") as f:
            json.dump(answers, f, sort_keys=True, indent=4)