Last active
December 26, 2021 11:43
-
-
Save sk-zk/9c411108bd469e15e17a93b9f3e8082f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "a6f9fc90", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import json\n", | |
"import requests\n", | |
"import csv" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "228977e5", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# ID of the map, which you can find in its URL\n", | |
"map_id = \"61c85283a6ffe20001cb59ff\"\n", | |
"url = \"https://www.geoguessr.com/api/v3/profiles/maps/\" + map_id\n", | |
"\n", | |
"# you need to be authenticated to edit your map, so copy paste your _ncfa cookie here\n", | |
"cookies = {\n", | |
" \"_ncfa\": \"\", \n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "e6c9623b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# get existing locs\n", | |
"locations = requests.get(url, cookies=cookies).json()[\"customCoordinates\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "ce56c5f5", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# load a CSV file in format panoid,lat,lng\n", | |
"# and append locs to the map\n", | |
"with open(\"picked.csv\", \"r\") as f:\n", | |
" reader = csv.reader(f, delimiter=',')\n", | |
" for row in reader:\n", | |
" panoId = row[0]\n", | |
" lat = row[1]\n", | |
" lng = row[2]\n", | |
" if any(x[\"panoId\"] == panoId for x in locations):\n", | |
" continue\n", | |
" locations.append({\n", | |
" \"panoId\": panoId,\n", | |
" \"lat\": lat, \n", | |
" \"lng\": lng,\n", | |
" })" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "c9cc921d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# submit locs\n", | |
"headers = {'Content-Type': 'application/json'}\n", | |
"r = requests.post(url, data=json.dumps({\n", | |
" \"customCoordinates\": locations\n", | |
"}), cookies=cookies, headers=headers)\n", | |
"r" | |
] | |
} | |
], | |
"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.9.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment