refactoring
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
"from KreisOptionsSetter import KreisOptionsSetter\n",
|
||||
"from TestHelper import TestHelper\n",
|
||||
"from IOUtils import IOUtils\n",
|
||||
"from Datawrapper import Datawrapper\n",
|
||||
"\n",
|
||||
"pd.set_option('display.max_rows', 100)\n",
|
||||
"pd.set_option('display.max_columns', None)\n",
|
||||
@@ -434,66 +435,6 @@
|
||||
"medianOfFreeBedsByKreisTable = createMedianOfFreeBedsByKreisTableForChoroplethMap(medianOfFreeBedsByKreisTableFactory)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b4247571",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import requests\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class Datawrapper:\n",
|
||||
"\n",
|
||||
" def __init__(self, accessToken):\n",
|
||||
" self.authHeader = {\"Authorization\": f\"Bearer {accessToken}\"}\n",
|
||||
"\n",
|
||||
" def setChartTitle(self, title):\n",
|
||||
" response = requests.request(\n",
|
||||
" \"PATCH\",\n",
|
||||
" \"https://api.datawrapper.de/v3/charts/dYmYb\",\n",
|
||||
" json={\"title\": title},\n",
|
||||
" headers={\n",
|
||||
" \"Accept\": \"*/*\",\n",
|
||||
" \"Content-Type\": \"application/json\"\n",
|
||||
" } | self.authHeader)\n",
|
||||
" return json.loads(response.text)\n",
|
||||
"\n",
|
||||
" def uploadChartData(self, data: pd.DataFrame):\n",
|
||||
" response = requests.request(\n",
|
||||
" \"PUT\",\n",
|
||||
" \"https://api.datawrapper.de/v3/charts/dYmYb/data\",\n",
|
||||
" data=data.to_csv(\n",
|
||||
" index=False,\n",
|
||||
" columns=['gemeindeschluessel', 'median_free_beds_in_percent', 'Kreis']).encode(\"utf-8\"),\n",
|
||||
" headers={\n",
|
||||
" \"Accept\": \"*/*\",\n",
|
||||
" \"Content-Type\": \"text/csv\"\n",
|
||||
" } | self.authHeader)\n",
|
||||
" return response.text\n",
|
||||
"\n",
|
||||
" def fetchChartData(self):\n",
|
||||
" response = requests.request(\n",
|
||||
" \"GET\",\n",
|
||||
" \"https://api.datawrapper.de/v3/charts/dYmYb/data\",\n",
|
||||
" headers={\n",
|
||||
" \"Accept\": \"text/csv\"\n",
|
||||
" } | self.authHeader)\n",
|
||||
"\n",
|
||||
" return response.text\n",
|
||||
"\n",
|
||||
" def publishChart(self):\n",
|
||||
" response = requests.request(\n",
|
||||
" \"POST\",\n",
|
||||
" \"https://api.datawrapper.de/v3/charts/dYmYb/publish\",\n",
|
||||
" headers={\n",
|
||||
" \"Accept\": \"*/*\"\n",
|
||||
" } | self.authHeader)\n",
|
||||
" return json.loads(response.text)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
||||
Reference in New Issue
Block a user