zaiffi commited on
Commit
f9dae53
·
verified ·
1 Parent(s): f723046

Upload 2 files

Browse files

Create a data directory in your application root
Store all pickle files in this directory instead of the root
Ensure the directory exists before trying to write files
Use proper path joining for cross-platform compatibility

Files changed (2) hide show
  1. .gitignore +6 -0
  2. app.py +8 -3
.gitignore CHANGED
@@ -77,3 +77,9 @@ coverage.xml
77
  local_settings.py
78
  db.sqlite3
79
  db.sqlite3-journal
 
 
 
 
 
 
 
77
  local_settings.py
78
  db.sqlite3
79
  db.sqlite3-journal
80
+
81
+ # Data directory
82
+ data/
83
+
84
+ # OS
85
+ Thumbs.db
app.py CHANGED
@@ -9,13 +9,18 @@ from io import BytesIO
9
  # Load environment variables
10
  load_dotenv()
11
 
 
 
 
 
12
  def load_pickle_from_url(url, local_filename):
13
- if os.path.exists(local_filename):
14
- with open(local_filename, 'rb') as f:
 
15
  return pickle.load(f)
16
  response = requests.get(url)
17
  response.raise_for_status()
18
- with open(local_filename, 'wb') as f:
19
  f.write(response.content)
20
  return pickle.load(BytesIO(response.content))
21
 
 
9
  # Load environment variables
10
  load_dotenv()
11
 
12
+ # Create data directory if it doesn't exist
13
+ DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
14
+ os.makedirs(DATA_DIR, exist_ok=True)
15
+
16
  def load_pickle_from_url(url, local_filename):
17
+ local_path = os.path.join(DATA_DIR, local_filename)
18
+ if os.path.exists(local_path):
19
+ with open(local_path, 'rb') as f:
20
  return pickle.load(f)
21
  response = requests.get(url)
22
  response.raise_for_status()
23
+ with open(local_path, 'wb') as f:
24
  f.write(response.content)
25
  return pickle.load(BytesIO(response.content))
26