diff --git a/challenge-1.ipynb b/challenge-1.ipynb
index d5dbad5..5a096d0 100644
--- a/challenge-1.ipynb
+++ b/challenge-1.ipynb
@@ -111,7 +111,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.13"
+ "version": "3.11.5"
},
"toc": {
"base_numbering": 1,
diff --git a/challenge-2.ipynb b/challenge-2.ipynb
index df5e7f0..984e3b7 100644
--- a/challenge-2.ipynb
+++ b/challenge-2.ipynb
@@ -10,7 +10,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 23,
"id": "9b373771",
"metadata": {},
"outputs": [],
@@ -18,7 +18,42 @@
"import requests\n",
"import json\n",
"import pandas as pd\n",
- "from getpass import getpass"
+ "from getpass import getpass\n",
+ "import folium\n",
+ "from pymongo import MongoClient"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "id": "a08c09e7",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "True"
+ ]
+ },
+ "execution_count": 24,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import os\n",
+ "from dotenv import load_dotenv\n",
+ "load_dotenv()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "id": "710215ec",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "token = os.getenv(\"token\")"
]
},
{
@@ -31,12 +66,460 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 27,
"id": "1d72f571",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'results': [{'fsq_id': '5cf510f0031320002cbd5af8',\n",
+ " 'categories': [{'id': 13035,\n",
+ " 'name': 'Coffee Shop',\n",
+ " 'short_name': 'Coffee Shop',\n",
+ " 'plural_name': 'Coffee Shops',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/coffeeshop_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13065,\n",
+ " 'name': 'Restaurant',\n",
+ " 'short_name': 'Restaurant',\n",
+ " 'plural_name': 'Restaurants',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/default_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 57,\n",
+ " 'geocodes': {'drop_off': {'latitude': 41.39243, 'longitude': 2.185926},\n",
+ " 'main': {'latitude': 41.392556, 'longitude': 2.185831},\n",
+ " 'roof': {'latitude': 41.392556, 'longitude': 2.185831}},\n",
+ " 'link': '/v3/places/5cf510f0031320002cbd5af8',\n",
+ " 'location': {'address': 'Calle de Buenaventura Muñoz, 31',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': '',\n",
+ " 'formatted_address': 'Calle de Buenaventura Muñoz, 31, 08018 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08018',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Orval Barcelona',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '4f7176cde4b0d1b3a40615ff',\n",
+ " 'categories': [{'id': 13034,\n",
+ " 'name': 'Café',\n",
+ " 'short_name': 'Café',\n",
+ " 'plural_name': 'Cafés',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/cafe_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13065,\n",
+ " 'name': 'Restaurant',\n",
+ " 'short_name': 'Restaurant',\n",
+ " 'plural_name': 'Restaurants',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/default_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'LikelyOpen',\n",
+ " 'distance': 100,\n",
+ " 'geocodes': {'main': {'latitude': 41.392081, 'longitude': 2.185666},\n",
+ " 'roof': {'latitude': 41.392081, 'longitude': 2.185666}},\n",
+ " 'link': '/v3/places/4f7176cde4b0d1b3a40615ff',\n",
+ " 'location': {'address': 'Lington, 17',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': 'Wellington',\n",
+ " 'formatted_address': 'Lington, 17 (Wellington), 08018 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08018',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Santa Fe',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '568426aa498ee1348b126991',\n",
+ " 'categories': [{'id': 13034,\n",
+ " 'name': 'Café',\n",
+ " 'short_name': 'Café',\n",
+ " 'plural_name': 'Cafés',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/cafe_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13035,\n",
+ " 'name': 'Coffee Shop',\n",
+ " 'short_name': 'Coffee Shop',\n",
+ " 'plural_name': 'Coffee Shops',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/coffeeshop_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13065,\n",
+ " 'name': 'Restaurant',\n",
+ " 'short_name': 'Restaurant',\n",
+ " 'plural_name': 'Restaurants',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/default_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 58,\n",
+ " 'geocodes': {'main': {'latitude': 41.3929, 'longitude': 2.185177},\n",
+ " 'roof': {'latitude': 41.3929, 'longitude': 2.185177}},\n",
+ " 'link': '/v3/places/568426aa498ee1348b126991',\n",
+ " 'location': {'address': 'Wellington 100-104',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': 'Almogàvers',\n",
+ " 'formatted_address': 'Wellington 100-104 (Almogàvers), 08018 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08018',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Xocoxavi',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '4ddd11a0fa766a6d794a65b5',\n",
+ " 'categories': [{'id': 13034,\n",
+ " 'name': 'Café',\n",
+ " 'short_name': 'Café',\n",
+ " 'plural_name': 'Cafés',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/cafe_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13065,\n",
+ " 'name': 'Restaurant',\n",
+ " 'short_name': 'Restaurant',\n",
+ " 'plural_name': 'Restaurants',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/default_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 270,\n",
+ " 'geocodes': {'drop_off': {'latitude': 41.39109, 'longitude': 2.182803},\n",
+ " 'main': {'latitude': 41.391189, 'longitude': 2.182878},\n",
+ " 'roof': {'latitude': 41.391189, 'longitude': 2.182878}},\n",
+ " 'link': '/v3/places/4ddd11a0fa766a6d794a65b5',\n",
+ " 'location': {'address': 'Roger de Flor, 32',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': '',\n",
+ " 'formatted_address': 'Roger de Flor, 32, 08018 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08018',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Granja Itaca',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '55f561af498ecd91cd9f1f4d',\n",
+ " 'categories': [{'id': 13003,\n",
+ " 'name': 'Bar',\n",
+ " 'short_name': 'Bar',\n",
+ " 'plural_name': 'Bars',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/nightlife/pub_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13035,\n",
+ " 'name': 'Coffee Shop',\n",
+ " 'short_name': 'Coffee Shop',\n",
+ " 'plural_name': 'Coffee Shops',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/coffeeshop_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13065,\n",
+ " 'name': 'Restaurant',\n",
+ " 'short_name': 'Restaurant',\n",
+ " 'plural_name': 'Restaurants',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/default_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'Unsure',\n",
+ " 'distance': 371,\n",
+ " 'geocodes': {'drop_off': {'latitude': 41.391951, 'longitude': 2.189766},\n",
+ " 'main': {'latitude': 41.39185, 'longitude': 2.189843},\n",
+ " 'roof': {'latitude': 41.39185, 'longitude': 2.189843}},\n",
+ " 'link': '/v3/places/55f561af498ecd91cd9f1f4d',\n",
+ " 'location': {'address': 'Carrer de Llull, 20',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': '',\n",
+ " 'formatted_address': 'Carrer de Llull, 20, 08005 Barcelona Barcelona',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08005',\n",
+ " 'region': 'Barcelona'},\n",
+ " 'name': 'Sacher Café',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '5d4f2d40833f8300086149ea',\n",
+ " 'categories': [{'id': 13034,\n",
+ " 'name': 'Café',\n",
+ " 'short_name': 'Café',\n",
+ " 'plural_name': 'Cafés',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/cafe_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13065,\n",
+ " 'name': 'Restaurant',\n",
+ " 'short_name': 'Restaurant',\n",
+ " 'plural_name': 'Restaurants',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/default_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 289,\n",
+ " 'geocodes': {'main': {'latitude': 41.390444, 'longitude': 2.185588}},\n",
+ " 'link': '/v3/places/5d4f2d40833f8300086149ea',\n",
+ " 'location': {'address': 'Pujades, 21',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': '',\n",
+ " 'formatted_address': 'Pujades, 21, 08018 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08018',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Flora Cafe',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '62e52eb959bae11f09c35d36',\n",
+ " 'categories': [{'id': 13034,\n",
+ " 'name': 'Café',\n",
+ " 'short_name': 'Café',\n",
+ " 'plural_name': 'Cafés',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/cafe_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 298,\n",
+ " 'geocodes': {'main': {'latitude': 41.391091, 'longitude': 2.183075}},\n",
+ " 'link': '/v3/places/62e52eb959bae11f09c35d36',\n",
+ " 'location': {'address': 'Carrer de Roger de Flor, 34',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': '',\n",
+ " 'formatted_address': 'Carrer de Roger de Flor, 34, 08018 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08018',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Boheme Artesans del Pa',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '6459e2fd9af08935f86b95c8',\n",
+ " 'categories': [{'id': 13035,\n",
+ " 'name': 'Coffee Shop',\n",
+ " 'short_name': 'Coffee Shop',\n",
+ " 'plural_name': 'Coffee Shops',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/coffeeshop_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [{'id': 'ab4c54c0-d68a-012e-5619-003048cad9da',\n",
+ " 'name': 'Starbucks'}],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 425,\n",
+ " 'geocodes': {'main': {'latitude': 41.392007, 'longitude': 2.180638}},\n",
+ " 'link': '/v3/places/6459e2fd9af08935f86b95c8',\n",
+ " 'location': {'address': 'Avenida de Vilanova, 3',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': '',\n",
+ " 'formatted_address': 'Avenida de Vilanova, 3, 08003 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08003',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Starbucks',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '4c87885dd8086dcb69b9a252',\n",
+ " 'categories': [{'id': 13034,\n",
+ " 'name': 'Café',\n",
+ " 'short_name': 'Café',\n",
+ " 'plural_name': 'Cafés',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/cafe_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13035,\n",
+ " 'name': 'Coffee Shop',\n",
+ " 'short_name': 'Coffee Shop',\n",
+ " 'plural_name': 'Coffee Shops',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/coffeeshop_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13065,\n",
+ " 'name': 'Restaurant',\n",
+ " 'short_name': 'Restaurant',\n",
+ " 'plural_name': 'Restaurants',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/default_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 371,\n",
+ " 'geocodes': {'main': {'latitude': 41.394873, 'longitude': 2.181733},\n",
+ " 'roof': {'latitude': 41.394873, 'longitude': 2.181733}},\n",
+ " 'link': '/v3/places/4c87885dd8086dcb69b9a252',\n",
+ " 'location': {'address': 'Calle Ribes, 29',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': 'C. Sicilia',\n",
+ " 'formatted_address': 'Calle Ribes, 29 (C. Sicilia), 08013 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08013',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Bracafe',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '4dcfb7dd1f6eb122709a7f32',\n",
+ " 'categories': [{'id': 13034,\n",
+ " 'name': 'Café',\n",
+ " 'short_name': 'Café',\n",
+ " 'plural_name': 'Cafés',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/cafe_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'LikelyOpen',\n",
+ " 'distance': 417,\n",
+ " 'geocodes': {'main': {'latitude': 41.394389, 'longitude': 2.180895}},\n",
+ " 'link': '/v3/places/4dcfb7dd1f6eb122709a7f32',\n",
+ " 'location': {'address': 'Nàpols, 96',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': '',\n",
+ " 'formatted_address': 'Nàpols, 96, 08013 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08013',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Nàpols Forn Degustació',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'}],\n",
+ " 'context': {'geo_bounds': {'circle': {'center': {'latitude': 41.3930198,\n",
+ " 'longitude': 2.1855589},\n",
+ " 'radius': 500}}}}"
+ ]
+ },
+ "execution_count": 27,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "lat = 41.3930198\n",
+ "lon = 2.1855589\n",
+ "\n",
+ "def requests_for_foursquare(query, lat, lon, radius=500, limit=10):\n",
+ "\n",
+ " url = f\"https://api.foursquare.com/v3/places/search?query={query}&ll={lat},{lon}&radius={radius}&limit={limit}\"\n",
+ "\n",
+ " headers = {\n",
+ " \"accept\": \"application/json\",\n",
+ " \"Authorization\": token\n",
+ " }\n",
+ " \n",
+ " try:\n",
+ " return requests.get(url, headers=headers).json()\n",
+ " except Exception as e:\n",
+ " print(\"Error:\", e)\n",
+ " return None\n",
+ "\n",
+ "\n",
+ "res = requests_for_foursquare(\"coffee\", lat, lon, radius=500, limit=10)\n",
+ "res"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 28,
+ "id": "c7c5e2bc",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " name | \n",
+ " location | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " Orval Barcelona | \n",
+ " Calle de Buenaventura Muñoz, 31 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " Santa Fe | \n",
+ " Lington, 17 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " Xocoxavi | \n",
+ " Wellington 100-104 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " Granja Itaca | \n",
+ " Roger de Flor, 32 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " Sacher Café | \n",
+ " Carrer de Llull, 20 | \n",
+ "
\n",
+ " \n",
+ " 5 | \n",
+ " Flora Cafe | \n",
+ " Pujades, 21 | \n",
+ "
\n",
+ " \n",
+ " 6 | \n",
+ " Boheme Artesans del Pa | \n",
+ " Carrer de Roger de Flor, 34 | \n",
+ "
\n",
+ " \n",
+ " 7 | \n",
+ " Starbucks | \n",
+ " Avenida de Vilanova, 3 | \n",
+ "
\n",
+ " \n",
+ " 8 | \n",
+ " Bracafe | \n",
+ " Calle Ribes, 29 | \n",
+ "
\n",
+ " \n",
+ " 9 | \n",
+ " Nàpols Forn Degustació | \n",
+ " Nàpols, 96 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " name location\n",
+ "0 Orval Barcelona Calle de Buenaventura Muñoz, 31\n",
+ "1 Santa Fe Lington, 17\n",
+ "2 Xocoxavi Wellington 100-104\n",
+ "3 Granja Itaca Roger de Flor, 32\n",
+ "4 Sacher Café Carrer de Llull, 20\n",
+ "5 Flora Cafe Pujades, 21\n",
+ "6 Boheme Artesans del Pa Carrer de Roger de Flor, 34\n",
+ "7 Starbucks Avenida de Vilanova, 3\n",
+ "8 Bracafe Calle Ribes, 29\n",
+ "9 Nàpols Forn Degustació Nàpols, 96"
+ ]
+ },
+ "execution_count": 28,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# your code here"
+ "names = [(res[\"results\"][i][\"name\"]) for i in range(10)]\n",
+ "location = [(res[\"results\"][i][\"location\"][\"address\"]) for i in range(10)]\n",
+ "new_dict = {}\n",
+ "new_dict[\"name\"] = names\n",
+ "new_dict[\"location\"] = location\n",
+ "df_coffe_shop = pd.DataFrame(new_dict)\n",
+ "df_coffe_shop"
]
},
{
@@ -49,12 +532,302 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 30,
"id": "fda8ddff",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "{'results': [{'fsq_id': '5b8521d489e490002cefef18',\n",
+ " 'categories': [{'id': 13035,\n",
+ " 'name': 'Coffee Shop',\n",
+ " 'short_name': 'Coffee Shop',\n",
+ " 'plural_name': 'Coffee Shops',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/coffeeshop_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13065,\n",
+ " 'name': 'Restaurant',\n",
+ " 'short_name': 'Restaurant',\n",
+ " 'plural_name': 'Restaurants',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/default_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 501,\n",
+ " 'geocodes': {'main': {'latitude': 41.397168, 'longitude': 2.183123},\n",
+ " 'roof': {'latitude': 41.397168, 'longitude': 2.183123}},\n",
+ " 'link': '/v3/places/5b8521d489e490002cefef18',\n",
+ " 'location': {'address': 'Ausiàs Marc, 151',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'formatted_address': 'Ausiàs Marc, 151, 08013 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08013',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Three Marks Coffee',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '5cb5ca8fb1538e002c03442c',\n",
+ " 'categories': [{'id': 13035,\n",
+ " 'name': 'Coffee Shop',\n",
+ " 'short_name': 'Coffee Shop',\n",
+ " 'plural_name': 'Coffee Shops',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/coffeeshop_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 618,\n",
+ " 'geocodes': {'main': {'latitude': 41.394562, 'longitude': 2.178425}},\n",
+ " 'link': '/v3/places/5cb5ca8fb1538e002c03442c',\n",
+ " 'location': {'address': 'Calle de Roger de Flor, 102',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': '',\n",
+ " 'formatted_address': 'Calle de Roger de Flor, 102, 08013 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08013',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Brew Coffee',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '52fafeb4498e411285ad33be',\n",
+ " 'categories': [{'id': 13003,\n",
+ " 'name': 'Bar',\n",
+ " 'short_name': 'Bar',\n",
+ " 'plural_name': 'Bars',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/nightlife/pub_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13034,\n",
+ " 'name': 'Café',\n",
+ " 'short_name': 'Café',\n",
+ " 'plural_name': 'Cafés',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/cafe_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13035,\n",
+ " 'name': 'Coffee Shop',\n",
+ " 'short_name': 'Coffee Shop',\n",
+ " 'plural_name': 'Coffee Shops',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/coffeeshop_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 834,\n",
+ " 'geocodes': {'drop_off': {'latitude': 41.388916, 'longitude': 2.177114},\n",
+ " 'main': {'latitude': 41.388989, 'longitude': 2.177167},\n",
+ " 'roof': {'latitude': 41.388989, 'longitude': 2.177167}},\n",
+ " 'link': '/v3/places/52fafeb4498e411285ad33be',\n",
+ " 'location': {'address': 'Pasatge Sert, 12',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': 'C. de Trafalgar',\n",
+ " 'formatted_address': 'Pasatge Sert, 12 (C. de Trafalgar), 08003 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08003',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'Nømad Coffee Lab & Shop',\n",
+ " 'related_places': {'children': []},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '4ffd87dde4b07010c000f79b',\n",
+ " 'categories': [{'id': 13002,\n",
+ " 'name': 'Bakery',\n",
+ " 'short_name': 'Bakery',\n",
+ " 'plural_name': 'Bakeries',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/bakery_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13034,\n",
+ " 'name': 'Café',\n",
+ " 'short_name': 'Café',\n",
+ " 'plural_name': 'Cafés',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/cafe_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13065,\n",
+ " 'name': 'Restaurant',\n",
+ " 'short_name': 'Restaurant',\n",
+ " 'plural_name': 'Restaurants',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/default_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 795,\n",
+ " 'geocodes': {'drop_off': {'latitude': 41.396334, 'longitude': 2.177097},\n",
+ " 'main': {'latitude': 41.396371, 'longitude': 2.177069},\n",
+ " 'roof': {'latitude': 41.396371, 'longitude': 2.177069}},\n",
+ " 'link': '/v3/places/4ffd87dde4b07010c000f79b',\n",
+ " 'location': {'address': 'Gran Vía de Les Corts Catalanes, 677',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': 'btwn c/ Nàpols & c/ Roger de Flor',\n",
+ " 'formatted_address': 'Gran Vía de Les Corts Catalanes, 677 (btwn c/ Nàpols & c/ Roger de Flor), 08013 Barcelona Catalunya',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08013',\n",
+ " 'region': 'Catalunya'},\n",
+ " 'name': 'El Petit Príncep',\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'},\n",
+ " {'fsq_id': '556d6217498ef50c5d323048',\n",
+ " 'categories': [{'id': 13003,\n",
+ " 'name': 'Bar',\n",
+ " 'short_name': 'Bar',\n",
+ " 'plural_name': 'Bars',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/nightlife/pub_',\n",
+ " 'suffix': '.png'}},\n",
+ " {'id': 13035,\n",
+ " 'name': 'Coffee Shop',\n",
+ " 'short_name': 'Coffee Shop',\n",
+ " 'plural_name': 'Coffee Shops',\n",
+ " 'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/coffeeshop_',\n",
+ " 'suffix': '.png'}}],\n",
+ " 'chains': [],\n",
+ " 'closed_bucket': 'VeryLikelyOpen',\n",
+ " 'distance': 1007,\n",
+ " 'geocodes': {'main': {'latitude': 41.397977, 'longitude': 2.195589},\n",
+ " 'roof': {'latitude': 41.397977, 'longitude': 2.195589}},\n",
+ " 'link': '/v3/places/556d6217498ef50c5d323048',\n",
+ " 'location': {'address': 'Calle de Pujades, 95',\n",
+ " 'admin_region': 'Cataluña',\n",
+ " 'country': 'ES',\n",
+ " 'cross_street': 'C. de Badajoz',\n",
+ " 'formatted_address': 'Calle de Pujades, 95 (C. de Badajoz), 08005 Barcelona',\n",
+ " 'locality': 'Barcelona',\n",
+ " 'postcode': '08005'},\n",
+ " 'name': \"Nømad Roaster's Home\",\n",
+ " 'related_places': {},\n",
+ " 'timezone': 'Europe/Madrid'}],\n",
+ " 'context': {'geo_bounds': {'circle': {'center': {'latitude': 41.3930198,\n",
+ " 'longitude': 2.1855589},\n",
+ " 'radius': 22000}}}}"
+ ]
+ },
+ "execution_count": 30,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "lat = 41.3930198\n",
+ "lon = 2.1855589\n",
+ "\n",
+ "def requests_for_foursquare(query, lat, lon, limit=5):\n",
+ "\n",
+ " url = f\"https://api.foursquare.com/v3/places/search?query={query}&ll={lat},{lon}&limit={limit}\"\n",
+ "\n",
+ " headers = {\n",
+ " \"accept\": \"application/json\",\n",
+ " \"Authorization\": token\n",
+ " }\n",
+ " \n",
+ " try:\n",
+ " return requests.get(url, headers=headers).json()\n",
+ " except Exception as e:\n",
+ " print(\"Error:\", e)\n",
+ " return None\n",
+ "\n",
+ "\n",
+ "coffee_shop = requests_for_foursquare(\"coffee\", lat, lon, limit=5)\n",
+ "coffee_shop"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "id": "084af8c1",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " name | \n",
+ " location | \n",
+ " lat | \n",
+ " lon | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " 0 | \n",
+ " Orval Barcelona | \n",
+ " Calle de Buenaventura Muñoz, 31 | \n",
+ " 41.392556 | \n",
+ " 2.185831 | \n",
+ "
\n",
+ " \n",
+ " 1 | \n",
+ " Santa Fe | \n",
+ " Lington, 17 | \n",
+ " 41.392081 | \n",
+ " 2.185666 | \n",
+ "
\n",
+ " \n",
+ " 2 | \n",
+ " Xocoxavi | \n",
+ " Wellington 100-104 | \n",
+ " 41.392900 | \n",
+ " 2.185177 | \n",
+ "
\n",
+ " \n",
+ " 3 | \n",
+ " Granja Itaca | \n",
+ " Roger de Flor, 32 | \n",
+ " 41.391189 | \n",
+ " 2.182878 | \n",
+ "
\n",
+ " \n",
+ " 4 | \n",
+ " Sacher Café | \n",
+ " Carrer de Llull, 20 | \n",
+ " 41.391850 | \n",
+ " 2.189843 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " name location lat lon\n",
+ "0 Orval Barcelona Calle de Buenaventura Muñoz, 31 41.392556 2.185831\n",
+ "1 Santa Fe Lington, 17 41.392081 2.185666\n",
+ "2 Xocoxavi Wellington 100-104 41.392900 2.185177\n",
+ "3 Granja Itaca Roger de Flor, 32 41.391189 2.182878\n",
+ "4 Sacher Café Carrer de Llull, 20 41.391850 2.189843"
+ ]
+ },
+ "execution_count": 31,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# your code here"
+ "names = [(res[\"results\"][i][\"name\"]) for i in range(5)]\n",
+ "location = [(res[\"results\"][i][\"location\"][\"address\"]) for i in range(5)]\n",
+ "lat = [(res[\"results\"][i][\"geocodes\"][\"main\"][\"latitude\"]) for i in range (5)]\n",
+ "lon = [(res[\"results\"][i][\"geocodes\"][\"main\"][\"longitude\"]) for i in range (5)]\n",
+ "new_dict = {}\n",
+ "new_dict[\"name\"] = names\n",
+ "new_dict[\"location\"] = location\n",
+ "new_dict[\"lat\"] = lat\n",
+ "new_dict[\"lon\"] = lon\n",
+ "\n",
+ "coffee_shops = pd.DataFrame(new_dict)\n",
+ "coffee_shops"
]
},
{
@@ -67,13 +840,81 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 35,
"id": "1fad5153",
- "metadata": {},
+ "metadata": {
+ "scrolled": true
+ },
"outputs": [],
"source": [
- "def foursquare_places (venue, coordinates):\n",
- " pass"
+ "def foursquare_places(venue, token):\n",
+ " endpoint = f'https://api.foursquare.com/v3/places/search?query={venue}'\n",
+ "\n",
+ " headers = {\n",
+ " \"accept\": \"application/json\",\n",
+ " \"Authorization\": token\n",
+ " }\n",
+ "\n",
+ " try:\n",
+ " response = requests.get(endpoint, headers=headers)\n",
+ " response.raise_for_status() \n",
+ " data = response.json()\n",
+ " venues = data['results']\n",
+ " results = []\n",
+ " for venue in venues:\n",
+ " name = venue['name']\n",
+ " location = venue['geocodes']['main']\n",
+ " lat = location.get('latitude')\n",
+ " lng = location.get('longitude')\n",
+ " results.append({\n",
+ " 'name': name,\n",
+ " 'lat': lat,\n",
+ " 'lng': lng\n",
+ " })\n",
+ " return results\n",
+ " except requests.exceptions.RequestException as e:\n",
+ " print(f\"Error: {e}\")\n",
+ " return []\n",
+ " \n",
+ "def export_to_json(results, output_directory, output_file):\n",
+ " try:\n",
+ " full_file_path = os.path.join(output_directory, output_file)\n",
+ " os.makedirs(output_directory, exist_ok=True)\n",
+ " with open(full_file_path, 'w') as json_file:\n",
+ " json.dump(results, json_file, indent=4)\n",
+ " print(f\"Data exported to '{full_file_path}'\")\n",
+ " return True\n",
+ " except Exception as e:\n",
+ " print(f\"Error: {e}\")\n",
+ " return False\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "fa4df72e",
+ "metadata": {},
+ "source": [
+ "Fer example:\n",
+ "\n",
+ "get_bookstores_madrid(\"starbucks\", [\"lat\", \"lon\"])\n",
+ "\n",
+ " if venue == \"starbucks\":\n",
+ " requests.get(f\"url.....starbucks)\n",
+ " \n",
+ " elif venue == \"restaurants\":\n",
+ " requests.get(f\"url.....restaurants)\n",
+ " \n",
+ " new_list = []\n",
+ " for i in res:\n",
+ " \n",
+ " dict_ = {\"name\":name,\n",
+ " \"lat\": lat,\n",
+ " \"lon\": lon}\n",
+ " \n",
+ " nre_list.append(dict_)\n",
+ " \n",
+ " return new_list"
]
},
{
@@ -86,12 +927,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 36,
"id": "7ac5f2a8",
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Data exported to 'data/coffe_shops.json'\n"
+ ]
+ }
+ ],
"source": [
- "# your code here"
+ "results = foursquare_places(\"caffe\", token)\n",
+ "output_directory = 'data/'\n",
+ "output_file_name = 'coffe_shops.json'\n",
+ "\n",
+ "result = export_to_json(results, output_directory, output_file_name)"
]
},
{
@@ -104,12 +957,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 38,
"id": "85b94955",
"metadata": {},
"outputs": [],
"source": [
- "# your code here"
+ "client = MongoClient(\"mongodb://localhost:27017\")\n",
+ "\n",
+ "db = client[\"Ironhack\"]\n",
+ "\n",
+ "data_file = 'data/coffe_shops.json'\n",
+ "\n",
+ "collection_name = \"ironcoffee\"\n",
+ "\n",
+ "with open(data_file, 'r') as json_file:\n",
+ " data = json.load(json_file)\n",
+ "\n",
+ "collection = db[collection_name]\n",
+ "collection.insert_many(data)\n",
+ "\n",
+ "client.close()"
]
}
],
@@ -129,7 +996,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.13"
+ "version": "3.11.5"
},
"toc": {
"base_numbering": 1,
diff --git a/challenge-3.ipynb b/challenge-3.ipynb
index 8d8d1d6..2a0f44a 100644
--- a/challenge-3.ipynb
+++ b/challenge-3.ipynb
@@ -10,11 +10,23 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"id": "9b373771",
"metadata": {},
"outputs": [],
- "source": []
+ "source": [
+ "from pymongo import MongoClient\n",
+ "import json\n",
+ "\n",
+ "# Specify the path to the JSON file\n",
+ "json_file_path = 'data/coffe_shops.json'\n",
+ "\n",
+ "# Read the JSON data from the file\n",
+ "with open(json_file_path, 'r') as json_file:\n",
+ " data = json.load(json_file)\n",
+ "\n",
+ "# Now, 'data' contains the JSON data as a Python data structure (e.g., a list of dictionaries)"
+ ]
},
{
"cell_type": "markdown",
@@ -26,7 +38,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"id": "644bbf42",
"metadata": {},
"outputs": [],
@@ -37,11 +49,318 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"id": "0938676d",
"metadata": {},
- "outputs": [],
- "source": []
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "Make this Notebook Trusted to load map: File -> Trust Notebook
"
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import folium\n",
+ "\n",
+ "map_center = [data[0]['lat'], data[0]['lng']]\n",
+ "coffee_map = folium.Map(location=map_center, zoom_start=15) \n",
+ "\n",
+ "for shop in data:\n",
+ " folium.Marker(\n",
+ " location=[shop['lat'], shop['lng']],\n",
+ " popup=shop['name']\n",
+ " ).add_to(coffee_map)\n",
+ "\n",
+ "coffee_map.save('coffee_shops_map.html')\n",
+ "\n",
+ "coffee_map\n"
+ ]
},
{
"cell_type": "markdown",
@@ -50,6 +369,14 @@
"source": [
"After pushing, view your own notebook on [nbviewer](https://nbviewer.org/)"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "b491b21b",
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
@@ -68,7 +395,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.13"
+ "version": "3.11.5"
},
"toc": {
"base_numbering": 1,
diff --git a/coffee_shops_map.html b/coffee_shops_map.html
new file mode 100644
index 0000000..06f5738
--- /dev/null
+++ b/coffee_shops_map.html
@@ -0,0 +1,279 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file