LLMatie/google_maps.ipynb

182 lines
9.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "c30b82a6-a77d-4f71-9ae9-6f883cb241db",
"metadata": {},
"outputs": [],
"source": [
"# AIzaSyAkUb_CaNH5kO1yihOeB7QUlFBm5qoBw-s\n",
"# https://developers.google.com/maps/documentation/places/web-service/text-search\n",
"\n",
"# https://developers.google.com/maps/documentation/places/web-service/usage-and-billing#advanced-textsearch"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d33dd2cd-1f38-48eb-b576-fabbcca22bb1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'places': [{'formattedAddress': '766A Plenty Rd, Reservoir VIC 3073, Australia', 'displayName': {'text': 'Melbourne Kebabs', 'languageCode': 'en'}}, {'formattedAddress': '939 High St, Reservoir VIC 3073, Australia', 'priceLevel': 'PRICE_LEVEL_INEXPENSIVE', 'displayName': {'text': 'Five Star Kebabs', 'languageCode': 'en'}}, {'formattedAddress': 'Summerhill Shopping Centre, 3/850 Plenty Rd, Reservoir VIC 3073, Australia', 'displayName': {'text': \"Steffey's Pizza & Kebab\", 'languageCode': 'en'}}, {'formattedAddress': '701 Plenty Rd, Reservoir VIC 3073, Australia', 'displayName': {'text': 'K Lish Spuds', 'languageCode': 'en'}}, {'formattedAddress': '258 Broadway, Reservoir VIC 3073, Australia', 'priceLevel': 'PRICE_LEVEL_INEXPENSIVE', 'displayName': {'text': 'Broadway Kebabs', 'languageCode': 'en'}}, {'formattedAddress': '42 Edwardes St, Reservoir VIC 3073, Australia', 'displayName': {'text': 'Tasty Slice Pizza & Kebab', 'languageCode': 'en'}}, {'formattedAddress': '299 Spring St, Reservoir VIC 3073, Australia', 'priceLevel': 'PRICE_LEVEL_MODERATE', 'displayName': {'text': 'Garlic Boyz Kebabs (Reservoir)', 'languageCode': 'en'}}, {'formattedAddress': 'beside metro petroleum station, 139 Spring St, Reservoir VIC 3073, Australia', 'displayName': {'text': 'Kebab At Reservoir', 'languageCode': 'en'}}, {'formattedAddress': '25 Massey Ave, Reservoir VIC 3073, Australia', 'displayName': {'text': 'Adana Sofra', 'languageCode': 'en'}}, {'formattedAddress': 'Latrobe University, Kingsbury Drive, Shop 6 The Agora, Bundoora VIC 3083, Australia', 'displayName': {'text': \"Charlie's Kebabs\", 'languageCode': 'en'}}, {'formattedAddress': '257 Plenty Rd, Preston VIC 3072, Australia', 'priceLevel': 'PRICE_LEVEL_INEXPENSIVE', 'displayName': {'text': 'Sams Kebabworx', 'languageCode': 'en'}}, {'formattedAddress': '299 Spring St, Reservoir VIC 3073, Australia', 'displayName': {'text': 'Cheesy Bite Pizza & Kebab - Reservoir', 'languageCode': 'en'}}, {'formattedAddress': 'Level G, 8/58 Mahoneys Rd, Thomastown VIC 3074, Australia', 'displayName': {'text': 'Kebab Crew Thomastown', 'languageCode': 'en'}}, {'formattedAddress': '415-417 Plenty Rd, Preston VIC 3072, Australia', 'displayName': {'text': 'Preston Kebabs', 'languageCode': 'en'}}, {'formattedAddress': '101 Bell St, Preston VIC 3072, Australia', 'priceLevel': 'PRICE_LEVEL_INEXPENSIVE', 'displayName': {'text': 'Ozzie Kebabs', 'languageCode': 'en'}}, {'formattedAddress': '10 Copernicus Cres, Bundoora VIC 3083, Australia', 'displayName': {'text': 'Kebab Centre', 'languageCode': 'en'}}, {'formattedAddress': '265 High St, Thomastown VIC 3074, Australia', 'priceLevel': 'PRICE_LEVEL_MODERATE', 'displayName': {'text': 'Melbourne Kebabs & Grill', 'languageCode': 'en'}}, {'formattedAddress': '2/50 Murray Rd, Preston VIC 3072, Australia', 'displayName': {'text': 'My Kebabz', 'languageCode': 'en'}}, {'formattedAddress': 'Shop 4/13 Edgars Rd, Thomastown VIC 3074, Australia', 'priceLevel': 'PRICE_LEVEL_INEXPENSIVE', 'displayName': {'text': 'Kebab 66 Thomastown', 'languageCode': 'en'}}, {'formattedAddress': '434 Bell St, Preston VIC 3072, Australia', 'priceLevel': 'PRICE_LEVEL_INEXPENSIVE', 'displayName': {'text': \"Haci's Kebabs\", 'languageCode': 'en'}}]}\n"
]
}
],
"source": [
"import requests\n",
"\n",
"def search_places(api_key, text_query):\n",
" url = \"https://places.googleapis.com/v1/places:searchText\"\n",
" headers = {\n",
" \"Content-Type\": \"application/json\",\n",
" \"X-Goog-Api-Key\": api_key,\n",
" \"X-Goog-FieldMask\": \"places.displayName,places.formattedAddress,places.priceLevel\" #,places.currentOpeningHours\" #, places.servesBeer\"\n",
" }\n",
" data = {\n",
" \"textQuery\": text_query\n",
" }\n",
" \n",
" response = requests.post(url, headers=headers, json=data)\n",
" \n",
" if response.status_code == 200:\n",
" return response.json()\n",
" else:\n",
" raise Exception(f\"Error: {response.status_code} - {response.text}\")\n",
"\n",
"# Example usage\n",
"API_KEY = \"AIzaSyAkUb_CaNH5kO1yihOeB7QUlFBm5qoBw-s\"\n",
"text_query = \"kebabs near 102 boldrewood parade\"\n",
"result = search_places(API_KEY, text_query)\n",
"print(result)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "cbca172f-302f-4890-a4f0-0b445387a2d5",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'places': [{'id': 'ChIJxwaS7MhF1moRu-TvQCWZJgQ'}, {'id': 'ChIJpQIlgp5F1moRRZAAP3ZuJAQ'}, {'id': 'ChIJm4Ddk3ZF1moRxcOb49wL4g4'}, {'id': 'ChIJgeHr56FF1moRkKeSS30qZno'}, {'id': 'ChIJP3yubWhF1moRSN1H12iqtdo'}, {'id': 'ChIJH4hNvjRF1moR0V3iIHSGUAc'}, {'id': 'ChIJ1-wvaaBF1moRt0lTcKJ-QPE'}, {'id': 'ChIJJeN0-JhF1moRDsY2ZFITbPI'}, {'id': 'ChIJxYY5shxF1moRUURTdMSW07s'}, {'id': 'ChIJX_c6veJF1moRCLdL81miOY4'}, {'id': 'ChIJy5F4_vRE1moREBmOaRu908A'}, {'id': 'ChIJEe5YKvVF1moRcoRRrVNLQKU'}, {'id': 'ChIJPXTpCABP1moRel7GFk5kBVA'}, {'id': 'ChIJKwFdIqBF1moR5hXQvAUGqv8'}, {'id': 'ChIJnXZIv0hE1moR1E4eDO4wp-o'}, {'id': 'ChIJVfTLyf9F1moRzFTymUVMJfg'}, {'id': 'ChIJATSuBA1P1moRnXwKO0QRQ-Q'}, {'id': 'ChIJPUotBKpF1moR9GINrBIFfZ4'}, {'id': 'ChIJYy2bOoBP1moRZakjXy8k0eA'}, {'id': 'ChIJoUMXgvFE1moRB0nttIq4Zi0'}]}\n"
]
}
],
"source": [
"import requests\n",
"\n",
"def search_places(api_key, text_query):\n",
" url = \"https://places.googleapis.com/v1/places:searchText\"\n",
" headers = {\n",
" \"Content-Type\": \"application/json\",\n",
" \"X-Goog-Api-Key\": api_key,\n",
" # \"X-Goog-FieldMask\": \"places.servesBeer, places.servesCoffee\"\n",
" \"X-Goog-FieldMask\": \"places.id\"\n",
" }\n",
" data = {\n",
" \"textQuery\": text_query\n",
" }\n",
" \n",
" response = requests.post(url, headers=headers, json=data)\n",
" \n",
" if response.status_code == 200:\n",
" return response.json()\n",
" else:\n",
" raise Exception(f\"Error: {response.status_code} - {response.text}\")\n",
"\n",
"# Example usage\n",
"API_KEY = \"AIzaSyAkUb_CaNH5kO1yihOeB7QUlFBm5qoBw-s\"\n",
"text_query = \"kebabs near 102 boldrewood parade\"\n",
"result = search_places(API_KEY, text_query)\n",
"print(result)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "2e7a6cbc-3d6a-4583-a66e-a90b7238db3b",
"metadata": {},
"outputs": [
{
"ename": "Exception",
"evalue": "Error: 404 - ",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mException\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[16], line 8\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(response\u001b[38;5;241m.\u001b[39mjson())\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m----> 8\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mError: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresponse\u001b[38;5;241m.\u001b[39mstatus_code\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m - \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresponse\u001b[38;5;241m.\u001b[39mtext\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mException\u001b[0m: Error: 404 - "
]
}
],
"source": [
"url=\"https://places.googleapis.com/v1/places/ChIJ05IRjKHxEQ0RJLV_5NLdK2w?fields=id&key=\" + API_KEY\n",
"\n",
"response = requests.post(url)\n",
"\n",
"if response.status_code == 200:\n",
" print(response.json())\n",
"else:\n",
" raise Exception(f\"Error: {response.status_code} - {response.text}\")"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7d70f88d-0cc9-42a5-b9c5-ec74169ca56c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'https://places.googleapis.com/v1/places/ChIJ05IRjKHxEQ0RJLV_5NLdK2w?fields=id&key=AIzaSyAkUb_CaNH5kO1yihOeB7QUlFBm5qoBw-s'"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"url"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "72daa6b1-3535-40f2-b6d8-f330662dc715",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.13.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}