Skip to content

Commit 49eb67e

Browse files
Breaking change: Remove JSON file support (#381)
2 parents 28f4f47 + 2f13ce2 commit 49eb67e

File tree

3 files changed

+3
-87
lines changed

3 files changed

+3
-87
lines changed

data/server.json

Lines changed: 0 additions & 64 deletions
This file was deleted.

docs/configuration/settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ A regular expression that the request's `sub` field must match.
105105

106106
### `IMPORT_FILE_PATH`\*
107107

108-
The path to file containing data to be imported into the server's database. Must be either CSV or JSON.
108+
The path to file containing data to be imported into the server's database. Must be CSV.
109109

110110
### `INPUT_HASH_ALGO`
111111

eligibility_server/db/setup.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import csv
2-
import json
32
from tempfile import NamedTemporaryFile
43

54
import click
@@ -36,7 +35,7 @@ def init_db_command():
3635

3736
def import_users():
3837
"""
39-
Imports user data to database, from either a local or remote JSON or CSV file,
38+
Imports user data to database, from either a local or remote CSV file,
4039
given the `IMPORT_FILE_PATH` setting.
4140
CSV files take extra settings: `CSV_DELIMITER`, `CSV_QUOTING`, `CSV_QUOTECHAR`
4241
"""
@@ -47,36 +46,17 @@ def import_users():
4746
format = path.split(".")[-1].lower()
4847
remote = path.lower().startswith("http")
4948

50-
if format not in ["json", "csv"]:
49+
if format not in ["csv"]:
5150
click.warning(f"File format is not supported: {format}")
5251
return
5352

54-
if format == "json":
55-
import_json_users(path, remote)
5653
elif format == "csv":
5754
import_csv_users(path, remote)
5855

5956
click.echo(f"Users added: {User.query.count()}")
6057
click.echo(f"Eligibility types added: {Eligibility.query.count()}")
6158

6259

63-
def import_json_users(json_path, remote):
64-
data = {}
65-
if remote:
66-
# download the file to a dict
67-
data = requests.get(json_path, timeout=config.request_timeout).json()
68-
else:
69-
# open the file and load to a dict
70-
with open(json_path) as file:
71-
data = json.load(file)
72-
if "users" in data:
73-
data = data["users"]
74-
# unpack from the key/value pairs in data
75-
# sub = [name, types]
76-
for sub, (name, types) in data.items():
77-
save_user(sub, name, types)
78-
79-
8060
def import_csv_users(csv_path, remote):
8161
# placeholder for a temp file that remote is downloaded to
8262
temp_csv = None

0 commit comments

Comments
 (0)