Skip to content

Commit

Permalink
Issues fixed
Browse files Browse the repository at this point in the history
Properly get the current dir for both .py and .exe file and generates accounts.json if not present instead of showing error.
  • Loading branch information
TechWhizKid authored Aug 19, 2023
1 parent 8e59bf6 commit 1700893
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pyFlaskyServe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import threading
import json
import secrets
import sys
from waitress import serve
from flask import Flask, render_template_string, request, send_file, session
from flask_limiter import Limiter
Expand All @@ -18,12 +19,25 @@
)


current_directory = os.path.dirname(os.path.abspath(__file__))
ignore_files = [f"{os.path.abspath(__file__)}",
# Get the directory where the executable or script is located
if getattr(sys, 'frozen', False): # If the code is compiled into an executable
current_directory = os.path.dirname(sys.executable)
else:
current_directory = os.path.dirname(os.path.abspath(__file__))

ignore_files = [f"{os.path.join(current_directory, __file__)}",
f"{os.path.join(current_directory, 'favicon.ico')}",
f"{os.path.join(current_directory, 'accounts.json')}"]


# Create a account.json file if not already present in current dir
user_accounts_file = os.path.join(current_directory, 'accounts.json')

if not os.path.exists(user_accounts_file):
with open(user_accounts_file, 'w') as file:
file.write("{}")


# Function to get the current working directory
def get_current_directory():
"""Get the current working directory.
Expand Down

0 comments on commit 1700893

Please sign in to comment.