-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |