Skip to content

Commit c91a703

Browse files
committed
changes to gitignore and sqltojson script
1 parent 62b3ff4 commit c91a703

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,7 @@ node_modules
147147
static/
148148

149149
data/**/*.md5
150+
data
151+
data/systems
150152

151153
.DS_Store

scripts/sqltojson.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
print("Error:", ex)
1616
exit(1)
1717

18-
query = "SELECT [surname] as staff_surname ,[forename1] as staff_forename, [dept_party_nm]as dept, [job_title],[boss_surname] as manager_surname FROM [Mich].[dbo].[ManagerDept]"
18+
query = "SELECT TOP (1000) [surname],[firstname] ,[job_title],[dept],[cn] as Fullname ,[mail],[samaccountname],[Phone],[managername],[managermail] FROM [Mich].[dbo].[ManagerDeptAD]"
1919
cursor = conn.cursor()
2020
cursor.execute(query)
2121

@@ -27,25 +27,14 @@
2727
for row in cursor.fetchall():
2828
data.append(dict(zip(columns, row)))
2929

30-
# Print the number of records fetched
31-
print(f"Number of records fetched: {len(data)}")
32-
33-
# Specify the directory where you want to save the JSON files
34-
output_dir_path = 'c:/NKCAI/nkcai/data/managerdept/'
35-
36-
# Make sure the directory exists
37-
os.makedirs(output_dir_path, exist_ok=True)
38-
39-
# Loop through the data list
40-
for i, record in enumerate(data):
41-
# Convert dictionary to JSON
42-
json_data = json.dumps(record, indent=4)
43-
44-
45-
# Create a unique file name for each record using the surname
46-
output_file_path = os.path.join(output_dir_path, f'{record["staff_surname"]}_{i}.json')
47-
48-
# Write JSON data to a file
49-
with open(output_file_path, 'w') as f:
50-
f.write(json_data)
51-
print(f"Data written to {output_file_path}")
30+
# Specify the path for the output JSON file
31+
output_file_path = 'c:/NKCAI/nkcai/data/managerdept/ManagerDeptAD.json'
32+
33+
# Convert the entire data list to JSON
34+
all_records_json = json.dumps(data, indent=4)
35+
36+
# Write the JSON data to a single file
37+
with open(output_file_path, 'w') as f:
38+
f.write(all_records_json)
39+
40+
print(f"All records written to {output_file_path}")

0 commit comments

Comments
 (0)