Skip to content

update defs script - #14

Merged
an-empty-string merged 1 commit into
mainfrom
as/update-defs-script
Aug 1, 2026
Merged

update defs script#14
an-empty-string merged 1 commit into
mainfrom
as/update-defs-script

Conversation

@ava-silver

@ava-silver ava-silver commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Cleans up the defs script, so now the file is defs.yml, and adds to the format a type field to each entry for either a turf or a group:

- name: issue-phonebank-1k
  type: turf
  ...
- name: Group 1
  type: group
  props:
    desc: Group 1
  turfs:
    - issue-phonebank-1k

Comment on lines +36 to +59
def get_by_external_id[
T: HasExternalId
](items: Collection[T], defs: list[T], save: Callable[[T], T]) -> dict[str, T]:
"""gets a dict of items (groups/turfs) by their external id,
updating the db if the `defs` dont already exist in `items`"""
items_by_external_id = {i.external_id: i for i in items if i.external_id}
for item in defs:
if item.external_id not in items_by_external_id:
items_by_external_id[item.external_id] = save(item)
return items_by_external_id


def make_list_of_defs[
T: Any
](constructor: type[T], configs: list[dict[str, Any]]) -> list[T]:
"constructs a list of the actual type based on the yaml defs"
return [
constructor(
external_id=config["name"],
created_by="system import",
**config.get("props", {}),
)
for config in configs
]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made these to unify the processing of defs/updating the database so copy/paste errors dont mess things up in the future

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank u

@an-empty-string an-empty-string left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm (looks golfcart to me)

Comment on lines +36 to +59
def get_by_external_id[
T: HasExternalId
](items: Collection[T], defs: list[T], save: Callable[[T], T]) -> dict[str, T]:
"""gets a dict of items (groups/turfs) by their external id,
updating the db if the `defs` dont already exist in `items`"""
items_by_external_id = {i.external_id: i for i in items if i.external_id}
for item in defs:
if item.external_id not in items_by_external_id:
items_by_external_id[item.external_id] = save(item)
return items_by_external_id


def make_list_of_defs[
T: Any
](constructor: type[T], configs: list[dict[str, Any]]) -> list[T]:
"constructs a list of the actual type based on the yaml defs"
return [
constructor(
external_id=config["name"],
created_by="system import",
**config.get("props", {}),
)
for config in configs
]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank u

turfs_by_external_id[config["name"]] = database.save_turf(
Turf(external_id=config["name"], created_by="system import")
def get_by_external_id[
T: HasExternalId

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hell yeah!!!

@an-empty-string
an-empty-string merged commit 985a013 into main Aug 1, 2026
2 checks passed
@ava-silver
ava-silver deleted the as/update-defs-script branch August 1, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants