Update app.py
Browse filesAdd source URL to the run_get_csp_data output
app.py
CHANGED
|
@@ -121,9 +121,14 @@ def get_query_values(topic_params: list[str] = []) -> List[Dict]:
|
|
| 121 |
except ValueError as ve:
|
| 122 |
raise RuntimeError(f"Parsing failed: {ve}")
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
def get_csp_data(lang: str = 'en', topic_params: list[str] = [], **kwargs) -> List[Dict]:
|
| 126 |
-
"""Get statistics from Official Statistics Portal of Latvia (CSP or Centrālā statistikas pārvalde).
|
| 127 |
|
| 128 |
Args:
|
| 129 |
lang (str): Language. Default value 'en'.
|
|
@@ -139,7 +144,7 @@ def get_csp_data(lang: str = 'en', topic_params: list[str] = [], **kwargs) -> Li
|
|
| 139 |
can be obtained using the function get_query_values.
|
| 140 |
'valueTexts' from get_query_values could help if 'values' is unclear.
|
| 141 |
Returns:
|
| 142 |
-
list: The list of the dictionaries, where dictionary's key 'key' contains query parameters and key 'values' contains values.
|
| 143 |
Examples:
|
| 144 |
>>> topics = ['POP', 'IR', 'IRE', 'IRE010']
|
| 145 |
>>> query_args = get_query_values(topics)
|
|
@@ -156,16 +161,11 @@ def get_csp_data(lang: str = 'en', topic_params: list[str] = [], **kwargs) -> Li
|
|
| 156 |
"""
|
| 157 |
csp2 = LVStat(lang, *topic_params)
|
| 158 |
csp2.set_query(**kwargs)
|
|
|
|
|
|
|
| 159 |
|
| 160 |
cspdata2 = csp2.get_data()
|
| 161 |
-
return cspdata2['data']
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
def construct_csp_link(params: list[str]) -> str:
|
| 165 |
-
base_url = 'https://data.stat.gov.lv/pxweb/lv/OSP_PUB/START__'
|
| 166 |
-
mid_path = '__'.join(params[:3])
|
| 167 |
-
last_part = params[3]
|
| 168 |
-
return f"{base_url}{mid_path}/{last_part}/"
|
| 169 |
|
| 170 |
|
| 171 |
with gr.Blocks() as demo:
|
|
|
|
| 121 |
except ValueError as ve:
|
| 122 |
raise RuntimeError(f"Parsing failed: {ve}")
|
| 123 |
|
| 124 |
+
def construct_csp_link(params: list[str]) -> str:
|
| 125 |
+
base_url = 'https://data.stat.gov.lv/pxweb/lv/OSP_PUB/START__'
|
| 126 |
+
mid_path = '__'.join(params[:3])
|
| 127 |
+
last_part = params[3]
|
| 128 |
+
return f"{base_url}{mid_path}/{last_part}/"
|
| 129 |
|
| 130 |
def get_csp_data(lang: str = 'en', topic_params: list[str] = [], **kwargs) -> List[Dict]:
|
| 131 |
+
"""Get statistics from Official Statistics Portal of Latvia (CSP or Centrālā statistikas pārvalde). Always cite 'Source URL' in the output.
|
| 132 |
|
| 133 |
Args:
|
| 134 |
lang (str): Language. Default value 'en'.
|
|
|
|
| 144 |
can be obtained using the function get_query_values.
|
| 145 |
'valueTexts' from get_query_values could help if 'values' is unclear.
|
| 146 |
Returns:
|
| 147 |
+
list: The list of the dictionaries, where dictionary's key 'key' contains query parameters and key 'values' contains values. First list element is data source (URL) from CSB.
|
| 148 |
Examples:
|
| 149 |
>>> topics = ['POP', 'IR', 'IRE', 'IRE010']
|
| 150 |
>>> query_args = get_query_values(topics)
|
|
|
|
| 161 |
"""
|
| 162 |
csp2 = LVStat(lang, *topic_params)
|
| 163 |
csp2.set_query(**kwargs)
|
| 164 |
+
|
| 165 |
+
link = construct_csp_link(topic_params)
|
| 166 |
|
| 167 |
cspdata2 = csp2.get_data()
|
| 168 |
+
return [{"Source URL": link}] + cspdata2['data']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
|
| 171 |
with gr.Blocks() as demo:
|