Skip to content

Commit

Permalink
Breaking change: Remove JSON file support (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
machikoyasuda authored Dec 7, 2023
2 parents 28f4f47 + 2f13ce2 commit 49eb67e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 87 deletions.
64 changes: 0 additions & 64 deletions data/server.json

This file was deleted.

2 changes: 1 addition & 1 deletion docs/configuration/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ A regular expression that the request's `sub` field must match.

### `IMPORT_FILE_PATH`\*

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

### `INPUT_HASH_ALGO`

Expand Down
24 changes: 2 additions & 22 deletions eligibility_server/db/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import csv
import json
from tempfile import NamedTemporaryFile

import click
Expand Down Expand Up @@ -36,7 +35,7 @@ def init_db_command():

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

if format not in ["json", "csv"]:
if format not in ["csv"]:
click.warning(f"File format is not supported: {format}")
return

if format == "json":
import_json_users(path, remote)
elif format == "csv":
import_csv_users(path, remote)

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


def import_json_users(json_path, remote):
data = {}
if remote:
# download the file to a dict
data = requests.get(json_path, timeout=config.request_timeout).json()
else:
# open the file and load to a dict
with open(json_path) as file:
data = json.load(file)
if "users" in data:
data = data["users"]
# unpack from the key/value pairs in data
# sub = [name, types]
for sub, (name, types) in data.items():
save_user(sub, name, types)


def import_csv_users(csv_path, remote):
# placeholder for a temp file that remote is downloaded to
temp_csv = None
Expand Down

0 comments on commit 49eb67e

Please sign in to comment.