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)
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
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())
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)
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)
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)
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
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)
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)
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
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
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
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
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
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
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)
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)
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
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)
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
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)
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)
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)
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
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)
def __init__(self, app, config): self.logger = getLogger(__name__) self.app = app self.config = config self._db = DB(app, config["sqlite"]["db"]) return
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
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)
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
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())