spideyrim commited on
Commit
30c866f
1 Parent(s): a007512

Upload grid.py

Browse files
Files changed (1) hide show
  1. grid.py +34 -0
grid.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ A small helper script to update the index.json from an ignored dir called "new"
3
+ """
4
+
5
+ import datetime
6
+ import json
7
+ import os
8
+
9
+ # Get today's date in ISO format
10
+ today = datetime.date.today().isoformat()
11
+
12
+ # Define the directory to scan
13
+ directory = 'new'
14
+
15
+ # Load the existing index.json file
16
+ with open('index.json', 'r') as f:
17
+ index = json.load(f)
18
+
19
+ # Initialize an empty dictionary to store the results
20
+ jpg_files = {}
21
+
22
+ # Loop over all files in the directory
23
+ for filename in os.listdir(directory):
24
+ # Check if the file is a JPEG image
25
+ if filename.endswith('.jpg'):
26
+ # Add the file to the dictionary with today's date as the value
27
+ jpg_files[filename] = today
28
+
29
+ # Update the "images" dictionary in the index
30
+ index['images'].update(jpg_files)
31
+
32
+ # Write the updated index back to the file with pretty formatting
33
+ with open('index.json', 'w') as f:
34
+ json.dump(index, f, indent=4)