pycensus.published_shares¶
Mode shares that exist only as figures in a published report (no table, no finer geography): each source module lists its figures and
the document they come from; :func:fetch downloads the document once into <cache>/published_shares/ and checks that every figure
is printed in its text (pdftotext, else pypdf; HTML pages as text), so a changed or moved publication fails loudly instead of silently.
document_text(url, cache_dir=None)
¶
Text of a published document (PDF or HTML), downloaded once into the cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Document URL. |
required |
cache_dir
|
Optional[str]
|
Cache folder; |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The text. |
fetch(figures, cache_dir=None, verify=True)
¶
figures: {key: {"transit_share": 0-1, "url": ..., "pattern": regex that must occur in the document, ...}} -> the same, checked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figures
|
Dict[str, dict]
|
Figures with their source and check pattern. |
required |
cache_dir
|
Optional[str]
|
Cache folder; |
None
|
verify
|
bool
|
Check each figure in its document. |
True
|
Returns:
| Type | Description |
|---|---|
Dict[str, dict]
|
The figures. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a figure's pattern is not found in its document. |