Skip to content

Commit

Permalink
add export example
Browse files Browse the repository at this point in the history
  • Loading branch information
ElJocho committed Feb 13, 2024
1 parent e112b28 commit f645c8b
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions export-example/hotosm_export_tool.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 35,
"id": "93f74c86-343d-43ee-8d39-e0bd99c86ad9",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import requests\n",
"import pandas"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "0a9a3038-3fef-448f-8a1d-f573c5dd735e",
"metadata": {},
"outputs": [],
"source": [
"# Export folder - Be Careful Python overwrites existing data silently!:\n",
"target_path = os.path.join(\"~/Documents/\", \"data\")\n",
"os.makedirs(target_path, exist_ok=True)\n",
"\n",
"# Hashtags: for each of these one csv report is generated\n",
"relevant_hashtags_list = [\"hotosm-project-*\", \"hotosm-project-15476\"]\n",
"\n",
"# Query Parameters:\n",
"startdate=\"2023-02-13T00:00:00Z\"\n",
"enddate=\"2024-02-13T23:59:59Z\"\n",
"iso3countryCodes = []\n",
"topics = [\"healthcare\", \"lulc\"]\n",
"\n",
"\n",
"data = {\n",
" \"startdate\": startdate,\n",
" \"enddate\": enddate,\n",
" \"countries\": \",\".join(iso3countryCodes)\n",
"}\n",
"\n",
"# big-numbers / summary section:\n",
"for hashtag in relevant_hashtags_list:\n",
" df = pandas.DataFrame(requests.get(f\"https://stats.now.ohsome.org/api/stats/{hashtag}\", params=data).json())\n",
" df = df.loc[ [\"changesets\",\"users\", \"roads\", \"buildings\", \"edits\",\"latest\"] , \"result\" ]\n",
" df_topics = pandas.DataFrame(requests.get(f\"https://stats.now.ohsome.org/api/topic/{','.join(topics)}\", params= data | {\"hashtag\": hashtag} ).json()[\"result\"])\n",
"\n",
" for column in df_topics.columns:\n",
" df[column] = df_topics[column][\"value\"]\n",
" \n",
" df.to_csv(os.path.join(target_path, f\"{hashtag}_{startdate}-{enddate}_{'-'.join(iso3countryCodes)}_{'-'.join(topics)}.csv\"))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit f645c8b

Please sign in to comment.