From 070235c452e539d844c01d8874539133c4a898bb Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Thu, 30 Nov 2023 10:02:05 +0200 Subject: [PATCH] switch to using .txt suffix. rename all your files! --- code/shop.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/code/shop.py b/code/shop.py index 42a18fa..ab1b72a 100644 --- a/code/shop.py +++ b/code/shop.py @@ -89,7 +89,7 @@ def get_shop_date(id): for row in cur.fetchall(): if id == row[0]: data_dir = os.path.join(DATADIR, get_username(row[2])) - data_file = os.path.join(data_dir, row[1] + ".md") + data_file = os.path.join(data_dir, row[1] + ".txt") if os.path.exists(data_file): date = datetime.datetime.fromtimestamp(os.path.getmtime(data_file)).strftime("%m/%d %H:%M") return date @@ -101,7 +101,7 @@ def get_shop_backup_date(id): for row in cur.fetchall(): if id == row[0]: data_dir = os.path.join(DATADIR, get_username(row[2])) - data_file = os.path.join(data_dir, row[1] + ".md.bkp") + data_file = os.path.join(data_dir, row[1] + ".txt.bkp") if os.path.exists(data_file): date = datetime.datetime.fromtimestamp(os.path.getmtime(data_file)).strftime("%m/%d %H:%M") return date @@ -120,7 +120,7 @@ def scan_for_new_documents(id): continue existing.append(row[1]) for row in os.listdir(data_dir): - if row.endswith(".md"): + if row.endswith(".txt"): if row[:-3] not in existing: non_existing.append(row[:-3]) for shop in non_existing: @@ -206,7 +206,7 @@ def show_shop(shopid): if not has_access: return redirect(url_for("list_shops")) data_dir = os.path.join(DATADIR, get_username(row[2])) - data_file = os.path.join(data_dir, row[1] + ".md") + data_file = os.path.join(data_dir, row[1] + ".txt") if not os.path.exists(data_file): open(data_file, "wt").close() entries = [] @@ -285,7 +285,7 @@ def add_items(): shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] ownername = get_username(ownerid) data_dir = os.path.join(DATADIR, ownername) - data_file = os.path.join(data_dir, shopname + ".md") + data_file = os.path.join(data_dir, shopname + ".txt") count = 0 contents_file = open(data_file, "at") for row in request.form["add_md"].split("\n"): @@ -307,7 +307,7 @@ def edit_md(): shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] ownername = get_username(ownerid) data_dir = os.path.join(DATADIR, ownername) - data_file = os.path.join(data_dir, shopname + ".md") + data_file = os.path.join(data_dir, shopname + ".txt") backup = data_file + ".bkp" copyfile(data_file, backup) contents_file = open(data_file, "wt") @@ -330,7 +330,7 @@ def restore_md(): shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] ownername = get_username(ownerid) data_dir = os.path.join(DATADIR, ownername) - data_file = os.path.join(data_dir, shopname + ".md") + data_file = os.path.join(data_dir, shopname + ".txt") backup = data_file + ".bkp" backup_tmp = data_file + ".tmp" if not os.path.exists(backup): @@ -365,7 +365,7 @@ def toggle_item(): if req_row == None: return redirect(url_for("show_shop", shopid=shopid)) data_dir = os.path.join(DATADIR, ownername) - data_file = os.path.join(data_dir, shopname + ".md") + data_file = os.path.join(data_dir, shopname + ".txt") backup = data_file + ".bkp" contents_file = open(data_file, "rt") contents = contents_file.read().split("\n") @@ -398,7 +398,7 @@ def remove_toggled(): shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] ownername = get_username(ownerid) data_dir = os.path.join(DATADIR, ownername) - data_file = os.path.join(data_dir, shopname + ".md") + data_file = os.path.join(data_dir, shopname + ".txt") backup = data_file + ".bkp" contents_file = open(data_file, "rt") contents = [] @@ -438,7 +438,7 @@ def add_shop(): g.db.execute("insert into shops (shop,owner) values (?, ?)", [shopname, session["user"]]) g.db.commit() new_dir = os.path.join(DATADIR, get_username(session["user"])) - new_file = os.path.join(new_dir, shopname + ".md") + new_file = os.path.join(new_dir, shopname + ".txt") if not os.path.exists(new_dir): os.mkdir(new_dir) open(new_file, "at") @@ -507,7 +507,7 @@ def remove_shop(): shopname = g.db.execute("select shop from shops where id=?", (request.form["shopid"],)).fetchall()[0][0] ownername = get_username(ownerid) data_dir = os.path.join(DATADIR, ownername) - data_file = os.path.join(data_dir, shopname + ".md") + data_file = os.path.join(data_dir, shopname + ".txt") if session.get("user") != ownerid: flash("Not your shop!") return redirect(url_for("show_shop", shopid=shopid))