Skip to content

Commit

Permalink
Run Black
Browse files Browse the repository at this point in the history
  • Loading branch information
psvenk committed Nov 30, 2024
1 parent bdb0e01 commit 68ff368
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions scrapers/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import json
import utils


def load_json_data(jsonfile):
"""
Loads data from the provided file
Expand All @@ -27,16 +28,17 @@ def load_json_data(jsonfile):
Returns:
* any: The data contained within the file
"""
with open(jsonfile, mode = "r", encoding = "utf-8") as f:
with open(jsonfile, mode="r", encoding="utf-8") as f:
return json.load(f)


def merge_data(datasets, keys_to_keep):
"""
Combines the provided datasets, retaining only keys from keys_to_keep.
NOTE: Later datasets will override earlier ones
Args:
* datasets (iterable[dict[any, dict]]):
* datasets (iterable[dict[any, dict]]):
* keys_to_keep (iterable): The keys to retain in the output
Returns:
Expand All @@ -49,6 +51,7 @@ def merge_data(datasets, keys_to_keep):
result[key].update(dataset[key])
return result


def run():
"""
The main entry point.
Expand All @@ -63,8 +66,8 @@ def run():
# If it's not in Fireroad, we don't have its schedule.
# If it's not in catalog, it's not offered this semester.
courses = merge_data(
datasets = [fireroad, catalog, overrides],
keys_to_keep = set(fireroad) & set(catalog)
datasets=[fireroad, catalog, overrides],
keys_to_keep=set(fireroad) & set(catalog),
)

term_info = utils.get_term_info()
Expand All @@ -75,7 +78,7 @@ def run():
"classes": courses,
}

with open("../public/latest.json", mode = "w", encoding = "utf-8") as f:
with open("../public/latest.json", mode="w", encoding="utf-8") as f:
json.dump(obj, f, separators=(",", ":"))
print(f"Got {len(courses)} courses")

Expand Down

0 comments on commit 68ff368

Please sign in to comment.