예제 #1
0
def init_db():
    with app.app_context():
        db = DB(app, config["sqlite"]["db"])
        if db.init_db(config["sqlite"]["schema"]):
            return ('Database Created/Reset', 200)
        else:
            return ("Something went horribly wrong", 500)
예제 #2
0
def load_app(configpath):
    global config
    config = yaml.safe_load(open(configpath))

    if not config["sqlite"]["db"].startswith('/'):
        config["sqlite"][
            "db"] = config["app_base_path"] + config["sqlite"]["db"]

    if not config["sqlite"]["schema"].startswith('/'):
        config["sqlite"][
            "schema"] = config["app_base_path"] + config["sqlite"]["schema"]

    logging.config.dictConfig(config["logging"])
    logging.info('Started')
    logger = getLogger(__name__)

    with app.app_context():
        logging.info('Clearing all cached programs.')
        db = DB(app, config["sqlite"]["db"])
        numrows = db.clear("programs")
        if numrows != None:
            logging.info('Expired resources deleted: ' + str(numrows))

    logger.info("Application loaded using config: {}".format(config))
    return app
예제 #3
0
def postEntry():
    try:
        if request.method == "OPTIONS":  # CORS preflight
            return _build_cors_prelight_response()
        args = request.args
        entry_vector = {}
        entry_data = {}
        for field in FIELDS_SEARCH:
            field_value = args.get(field)
            if field_value:
                field_value = int(field_value)
            entry_vector[field] = field_value
        for field in FIELDS_RESULT:
            entry_data[field] = args.get(field)

        print("Received entry:")
        pprint.pprint(entry_vector)
        pprint.pprint(entry_data)
        DB.addEntry(entry_vector, entry_data)

        return_list = {
            'Search parameters': entry_vector,
            'Outcome parameters': entry_data
        }
        return return_list
    except Exception:
        print(traceback.format_exc())
        raise InvalidUsage(traceback.format_exc())
예제 #4
0
    def archive(dbfile, id):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute("UPDATE termine SET archiviert = 1 WHERE oid = ?", [id])

        db.disconnect(conn, True)
예제 #5
0
    def done(dbfile, id):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute("UPDATE termine SET erledigt = 1 WHERE oid = ?", [id])

        db.disconnect(conn, True)
예제 #6
0
    def put(dbfile, klient):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute(
            "INSERT INTO klienten (vorname, nachname, geburtsdatum, archiviert) VALUES (?, ? ,?, ?)",
            [klient['vorname'], klient['nachname'], klient['geburtsdatum'], 0])
        db.disconnect(conn, True)
예제 #7
0
    def terminarten(dbfile):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute("SELECT oid, name, icon FROM terminarten ORDER BY name ASC")
        terminarten = c.fetchall()

        db.disconnect(conn, False)

        return terminarten
예제 #8
0
def etags(delim=''):
    with app.app_context():
        db = DB(app, config["sqlite"]["db"])
        results = db.etags()
        if results != None:
            output = "id        fcrepo_id       etag\n"
            for i in results:
                output += str(i[0]) + "     " + i[1] + "        " + i[2] + "\n"
            response = Response(output)
            response.headers['Content-type'] = "text/plain"
            return (response, 200)
        else:
            return ("Results was None?", 500)
예제 #9
0
def resources():
    with app.app_context():
        db = DB(app, config["sqlite"]["db"])
        results = db.rows("resources")
        if results != None:
            output = "id        cacheTimeout       uri\n"
            for i in results:
                output += str(i[0]) + "     " + i[1] + "        " + i[2] + "\n"
            response = Response(output)
            response.headers['Content-type'] = "text/plain"
            return (response, 200)
        else:
            return ("Results was None?", 500)
예제 #10
0
    def categories(dbfile):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute("SELECT oid, name  FROM kategorien ORDER BY name ASC")
        kategorien = c.fetchall()

        db.disconnect(conn, False)

        return kategorien
예제 #11
0
    def getsingle(dbfile, id):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute("SELECT oid, * FROM dokumente WHERE oid = ?", [id])
        dox = c.fetchone()

        db.disconnect(conn, False)

        return dox
예제 #12
0
    def getbydate(dbfile, date):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute("SELECT oid, * FROM dokumente WHERE add_datum = ?", [date])
        dox = c.fetchall()

        db.disconnect(conn, False)

        return dox
예제 #13
0
    def getbycategory(dbfile, kat):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute("SELECT oid, * FROM dokumente WHERE kategorie = ?", [kat])
        dox = c.fetchall()

        db.disconnect(conn, False)

        return dox
예제 #14
0
    def get(dbfile, klient_id):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute("SELECT oid, * FROM dokumente WHERE klient_id = ?", [id])
        dox = c.fetchall()

        db.disconnect(conn, False)

        return dox
예제 #15
0
    def __init__(self, refid, env="quality"):

        self.timeBwPage = 0.5

        assert env == "quality" or env == "prod", (
            "env value should be either quality or prod")
        self.env = env
        self.screenshotDir = os.path.join(os.getcwd(), "Screenshots")
        self.ocr = GcpOcr("gcp.json")
        self.readConfig()
        self.CreateS3()
        self.dbObj = DB(**self.dbConfig)
        self.refid = refid
예제 #16
0
def clearexpired():
    with app.app_context():
        db = DB(app, config["sqlite"]["db"])

        sql_query = "DELETE FROM resources WHERE ? > cacheTimeout"
        values = (datetime.datetime.now(), )
        numrows = db.update(sql_query, values)
        if numrows != None:
            output = "Expired resources deleted: " + str(numrows)
            response = Response(output)
            response.headers['Content-type'] = "text/plain"
            return (response, 200)
        else:
            return ("Results was None?", 500)
예제 #17
0
def pd_statuses(delim=''):
    with app.app_context():
        db = DB(app, config["sqlite"]["db"])
        results = db.pd_statuses()
        if results != None:
            output = "id        fcrepo_image_id       public_domain     last_checked\n"
            for i in results:
                output += str(i[0]) + "     " + i[1] + "        " + str(
                    i[2]) + "        " + i[3] + "\n"
            response = Response(output)
            response.headers['Content-type'] = "text/plain"
            return (response, 200)
        else:
            return ("Results was None?", 500)
예제 #18
0
    def get(dbfile):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute(
            "SELECT oid, * FROM klienten ORDER BY nachname, vorname DESC")
        klienten = c.fetchall()

        db.disconnect(conn, False)

        return klienten
예제 #19
0
    def update(dbfile, klient):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute(
            "UPDATE klienten SET vorname = ?, nachname = ?, geburtsdatum = ? WHERE oid = ?",
            [
                klient['vorname'], klient['nachname'], klient['geburtsdatum'],
                klient['id']
            ])
        db.disconnect(conn, True)
예제 #20
0
    def get(dbfile):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute(
            "SELECT t.oid, t.*, k.vorname, k.nachname, k.archiviert AS klient_archiviert, ta.name, ta.icon FROM termine t LEFT JOIN klienten k ON(k.oid = t.klient_id) LEFT JOIN terminarten ta ON(ta.oid = t.terminart) WHERE k.archiviert = 0 ORDER BY t.beginndatum, t.ablaufdatum ASC"
        )
        termine = c.fetchall()

        db.disconnect(conn, False)

        return termine
예제 #21
0
    def put(dbfile, termin):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute(
            "INSERT INTO termine (terminart, klient_id, beginndatum, ablaufdatum, kommentar, bearbeitungskommentar, archiviert) VALUES (?, ?, ?, ?, ?, ?, ?)",
            [
                termin['terminart'], termin['klient_id'],
                termin['beginndatum'], termin['ablaufdatum'],
                termin['kommentar'], termin['bearbeitungskommentar'], 0
            ])

        db.disconnect(conn, True)
예제 #22
0
def init_db(delim=''):
    with app.app_context():
        db = DB(app, config["sqlite"]["db"])
        if delim == "public_domain":
            if db.init_db(config["sqlite"]["pdschema"]):
                return ('Database Created/Reset for public_domain info', 200)
            else:
                return ("Something went horribly wrong for public_domain info",
                        500)
        elif delim == "assets" or delim == "images":
            if db.init_db(config["sqlite"]["schema"]):
                return ('Database Created/Reset for etag info', 200)
            else:
                return ("Something went horribly wrong for etag info", 500)
        else:
            return ("Not Found", 404)
예제 #23
0
def clear_table(db_name):
    with app.app_context():
        logging.info('Clearing all rows from table: ' + db_name)
        db = DB(app, config["sqlite"]["db"])
        numrows = db.clear(db_name)
        if numrows != None:
            line = 'Number of rows deleted from ' + db_name + ': ' + str(
                numrows)
            logging.info(line)
            response = Response(line)
            response.headers['Content-type'] = "text/plain"
            return (response, 200)
        else:
            line = "Failed to delete rows from table: " + db_name + " -- Mind you, there may have been no rows to delete."
            logging.info(line)
            logging.info("numrows was: {}".format(numrows))
            return (line, 500)
예제 #24
0
    def __init__(self, app, config, fcrepo_id):
        self.logger = getLogger(__name__)
        self.app = app
        self.config = config
        self.fcrepo_id = fcrepo_id
        self.session = requests.Session()
        if "enviro" not in config:
            self.session.proxies = {
                "http": "http://sysprox.artic.edu:3128",
                "https": "http://sysprox.artic.edu:3128",
            }
        if self._valid_fcrepo_id(fcrepo_id):
            self.dhurl = "http://aggregator-data.artic.edu/api/v1/artworks/search?cache=false&query[bool][should][][term][image_id]=" + self.fcrepo_id + "&query[bool][should][][term][alt_image_ids]=" + self.fcrepo_id + "&fields=is_public_domain,id,is_zoomable,max_zoom_window_size,api_link,title,artist_display"
        self._db = DB(app, config["sqlite"]["db"])

        self.logger.debug("fcrepo_id is: {}".format(self.fcrepo_id))
        return
예제 #25
0
    def update(dbfile, termin):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute(
            "UPDATE termine SET terminart = ?, klient_id = ?, beginndatum = ?, ablaufdatum = ?, kommentar = ?, bearbeitungskommentar = ? WHERE oid = ?",
            [
                termin['terminart'], termin['klient_id'],
                termin['beginndatum'], termin['ablaufdatum'],
                termin['kommentar'], termin['bearbeitungskommentar'],
                termin['id']
            ])

        db.disconnect(conn, True)
예제 #26
0
    def __init__(self, app, config):
        self.logger = getLogger(__name__)
        self.app = app
        self.config = config

        self._db = DB(app, config["sqlite"]["db"])

        return
예제 #27
0
    def __init__(self, app, config, fcrepo_id):
        self.logger = getLogger(__name__)
        self.app = app
        self.config = config
        self.fcrepo_id = fcrepo_id
        self.session = requests.Session()
        if self._valid_fcrepo_id(fcrepo_id):
            self.fcrepo_path = fcrepo_path_from_hash(fcrepo_id)
        else:
            self.fcrepo_path = '/' + fcrepo_id
        self.url = self.config["httpresolver"][
            "prefix"] + self.fcrepo_path + self.config["httpresolver"][
                "postfix"]
        self._db = DB(app, config["sqlite"]["db"])

        self.logger.debug("fcrepo_id is: {}".format(self.fcrepo_id))
        self.logger.debug("fcrepo_path is: {}".format(self.fcrepo_path))
        return
예제 #28
0
    def setup_terminarten(dbfile):

        terminarten = []

        terminarten.append({'name': 'Grundsicherung', 'icon': 'money'})
        terminarten.append({'name': 'Hartz IV', 'icon': 'money'})
        terminarten.append({'name': 'Wohngeld', 'icon': 'money'})
        terminarten.append({'name': 'BaFOEg', 'icon': 'money'})
        terminarten.append({'name': 'Kindergeld', 'icon': 'money'})
        terminarten.append({'name': 'Jahresbericht', 'icon': 'file-text-o'})
        terminarten.append({'name': 'Rechnungslegung', 'icon': 'file-excel-o'})
        terminarten.append({'name': 'GEZ-Befreiung', 'icon': 'television'})
        terminarten.append({
            'name': 'Schwerbehindertenausweis',
            'icon': 'id-card-o'
        })
        terminarten.append({'name': 'Sonstiges', 'icon': 'bell-o'})
        terminarten.append({'name': 'Rechnungslegung', 'icon': 'file-excel-o'})
        terminarten.append({'name': 'Beiblatt', 'icon': 'id-card-o'})
        terminarten.append({'name': 'Rentenantrag', 'icon': 'money'})
        terminarten.append({'name': 'ABW LWL', 'icon': 'money'})
        terminarten.append({
            'name': 'Ambulante Eingliederungshilfe',
            'icon': 'money'
        })
        terminarten.append({
            'name': 'Eingliederungshilfe Werkstatt',
            'icon': 'money'
        })

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        for t in terminarten:
            c.execute(
                "INSERT OR IGNORE INTO terminarten (name, icon) VALUES (?, ?)",
                [t['name'], t['icon']])

        db.disconnect(conn, True)
예제 #29
0
    def archive(dbfile, id):

        db = DB()

        conn = db.connect(dbfile)
        c = conn.cursor()

        c.execute("SELECT archiviert FROM klienten WHERE oid = ?", [id])
        archived = c.fetchone()

        if (archived['archiviert'] == 0):
            c.execute("UPDATE klienten SET archiviert = 1 WHERE oid = ?", [id])
        else:
            c.execute("UPDATE klienten SET archiviert = 0 WHERE oid = ?", [id])

        c.execute("SELECT oid, archiviert FROM klienten WHERE oid = ?", [id])
        klient = c.fetchone()

        db.disconnect(conn, True)

        return klient
예제 #30
0
def search():
    try:
        if request.method == "OPTIONS":  # CORS preflight
            print("Sending preflight check")
            return _build_cors_prelight_response()
        args = request.args
        search_vector = {}
        for field in FIELDS_SEARCH:
            field_value = args.get(field)
            if field_value:
                field_value = int(field_value)
            search_vector[field] = field_value

        search_result = DB.getEntries(search_vector)
        filepath = analyze(search_result)
        response = send_file(filepath, mimetype='image/png')
        response.headers.add("Access-Control-Allow-Origin", "*")
        return response
    except Exception:
        print(traceback.format_exc())
        raise InvalidUsage(traceback.format_exc())