discry.history
¶
Write the snapshot and append new rows to the history log.
load_json
¶
Read a JSON file, or return default when it is missing or empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
File to read. |
required |
default
|
Any
|
Value used when the file is absent or blank. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Parsed JSON, or |
dump_json
¶
Write JSON, creating parent directories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Destination file. |
required |
payload
|
Any
|
Value the JSON writer can encode. |
required |
settings
|
Settings | None
|
Indent, key order, and trailing newline.
Defaults to |
None
|
history_key
¶
Return the identity used to decide whether a history row is new.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
Mapping[str, Any]
|
History row or an equivalent mapping. |
required |
key_fields
|
tuple[str, ...] | None
|
Fields that form the key. None uses the default channel, build number, version hash, and capabilities. An empty version hash falls back to the build id. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Any, ...]
|
tuple[Any, ...]: One entry per key field. |
merge_history
¶
Build the latest snapshot and append unseen surfaces to history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
history
|
list[Mapping[str, Any]]
|
Rows already stored. |
required |
surfaces
|
list[ClientSurface]
|
Surfaces from this run. |
required |
scraped_at
|
datetime | None
|
Timestamp stored on new rows. None uses the settings clock. |
None
|
settings
|
Settings | None
|
Field lists, formats, and the clock.
Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
tuple[dict[str, Any], list[Mapping[str, Any]]]: Latest document, then the |
list[Mapping[str, Any]]
|
combined history. |
write_data_files
¶
Write the snapshot and the history log.
latest_formats chooses the snapshot files. An empty list uses
output_formats. History uses output_formats.
The JSON history file is the append log. It is updated even when json
is not one of the output formats, so later runs can still see old rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dir
|
Path
|
Directory used when a format's directory is unset. |
required |
surfaces
|
list[ClientSurface]
|
Surfaces from this run. |
required |
scraped_at
|
datetime | None
|
Timestamp stored on new rows. |
None
|
settings
|
Settings | None
|
Formats, paths, and fields. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
list[Path]: Files that were written. |
Raises:
| Type | Description |
|---|---|
TypeError
|
The JSON history file exists and is not an array. |