Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7fc02de

Browse files
committedMay 8, 2023
updates
1 parent 70da688 commit 7fc02de

File tree

1 file changed

+61
-43
lines changed

1 file changed

+61
-43
lines changed
 

‎002_scraping.ipynb

+61-43
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
"lat = \"47.1227347\"\n",
219219
"lon = \"8.1855324\"\n",
220220
"date = \"2020-05-01\"\n",
221-
"api_key = \"4aGLgbow4rdiRJqOF12KuHOxERGdZcVZO7NaiomC\"\n",
221+
"api_key = \"\"\n",
222222
"dim = \"0.1\"\n",
223223
"\n",
224224
"url = f\"https://api.nasa.gov/planetary/earth/imagery?lon={lon}&lat={lat}&date={date}&dim={dim}&api_key={api_key}\"\n",
@@ -229,15 +229,15 @@
229229
"base_uri": "https://localhost:8080/"
230230
},
231231
"id": "HIFFxI1vy90M",
232-
"outputId": "d1080e99-fa90-4978-e971-779efc9f655f"
232+
"outputId": "fed560e5-1b49-4b98-d377-77b8d3d694c0"
233233
},
234-
"execution_count": 11,
234+
"execution_count": 51,
235235
"outputs": [
236236
{
237237
"output_type": "stream",
238238
"name": "stdout",
239239
"text": [
240-
"https://api.nasa.gov/planetary/earth/imagery?lon=8.1855324&lat=47.1227347&date=2020-05-01&dim=0.1&api_key=4aGLgbow4rdiRJqOF12KuHOxERGdZcVZO7NaiomC\n"
240+
"https://api.nasa.gov/planetary/earth/imagery?lon=8.1855324&lat=47.1227347&date=2020-05-01&dim=0.1&api_key=\n"
241241
]
242242
}
243243
]
@@ -372,7 +372,7 @@
372372
"source": [
373373
"## Get images from specific locations\n",
374374
"\n",
375-
"We are preparing a `locations.csv` file with a couple of location points (lat,long) seperated with a comma. Make sure you store a locations.csv file in your sample_data directory:"
375+
"We are preparing a `locations.csv` file with a couple of location points (lat,long) seperated with a comma. Make sure you store a locations.csv file in your sample_data directory. Downloading with `wget` directly into the google drive:"
376376
],
377377
"metadata": {
378378
"id": "Ji8VG22889Im"
@@ -381,50 +381,14 @@
381381
{
382382
"cell_type": "code",
383383
"source": [
384-
"with (open(\"sample_data/locations.csv\") as f):\n",
385-
" locations = f.readlines()[1:]\n",
386-
"\n",
387-
"for location in locations[:5]: # read only first five entries\n",
388-
" place = location.strip().split(\",\")\n",
389-
" lat = place[2]\n",
390-
" lon = place[1]\n",
391-
" #print(f\"lat: {place[2]} lon: {place[1]} \")\n",
392-
" url = f\"https://api.nasa.gov/planetary/earth/imagery?lon={lon}&lat={lat}&date={date}&dim={dim}&api_key={api_key}\"\n",
393-
" print(url)"
384+
"!wget https://raw.githubusercontent.com/fleshgordo/scrapinghub/main/data/locations.csv -O sample_data/locations.csv "
394385
],
395386
"metadata": {
396387
"colab": {
397388
"base_uri": "https://localhost:8080/"
398389
},
399-
"id": "o3ocl-Ro9WOG",
400-
"outputId": "c54d4338-6cdd-47f9-afba-007943d74f85"
401-
},
402-
"execution_count": 42,
403-
"outputs": [
404-
{
405-
"output_type": "stream",
406-
"name": "stdout",
407-
"text": [
408-
"https://api.nasa.gov/planetary/earth/imagery?lon=87.82472222222222&lat=-70.17777777777778&date=2016-05-01&dim=0.1&api_key=4aGLgbow4rdiRJqOF12KuHOxERGdZcVZO7NaiomC\n",
409-
"https://api.nasa.gov/planetary/earth/imagery?lon=114.4525&lat=16.071666666666665&date=2016-05-01&dim=0.1&api_key=4aGLgbow4rdiRJqOF12KuHOxERGdZcVZO7NaiomC\n",
410-
"https://api.nasa.gov/planetary/earth/imagery?lon=81.22333333333333&lat=31.219166666666666&date=2016-05-01&dim=0.1&api_key=4aGLgbow4rdiRJqOF12KuHOxERGdZcVZO7NaiomC\n",
411-
"https://api.nasa.gov/planetary/earth/imagery?lon=77.35&lat=39.166666666666664&date=2016-05-01&dim=0.1&api_key=4aGLgbow4rdiRJqOF12KuHOxERGdZcVZO7NaiomC\n",
412-
"https://api.nasa.gov/planetary/earth/imagery?lon=81.27111111111111&lat=30.15583333333333&date=2016-05-01&dim=0.1&api_key=4aGLgbow4rdiRJqOF12KuHOxERGdZcVZO7NaiomC\n"
413-
]
414-
}
415-
]
416-
},
417-
{
418-
"cell_type": "code",
419-
"source": [
420-
"!wget https://raw.githubusercontent.com/fleshgordo/scrapinghub/main/data/locations.csv -O sample_data/locations.csv "
421-
],
422-
"metadata": {
423390
"id": "iyrR7XQ5-AjA",
424-
"outputId": "fda0c70a-1552-4bee-c615-d48ac0236c36",
425-
"colab": {
426-
"base_uri": "https://localhost:8080/"
427-
}
391+
"outputId": "fda0c70a-1552-4bee-c615-d48ac0236c36"
428392
},
429393
"execution_count": 25,
430394
"outputs": [
@@ -446,6 +410,60 @@
446410
]
447411
}
448412
]
413+
},
414+
{
415+
"cell_type": "code",
416+
"source": [
417+
"with (open(\"sample_data/locations.csv\") as f):\n",
418+
" locations = f.readlines()[1:]\n",
419+
"\n",
420+
"date = \"2016-01-01\"\n",
421+
"for location in locations[:5]: # read only first five entries\n",
422+
" place = location.strip().split(\",\")\n",
423+
" lat = place[2]\n",
424+
" lon = place[1]\n",
425+
" #print(f\"lat: {place[2]} lon: {place[1]} \")\n",
426+
" url = f\"https://api.nasa.gov/planetary/earth/imagery?lon={lon}&lat={lat}&date={date}&dim={dim}&api_key={api_key}\"\n",
427+
" print(url)\n",
428+
" download = requests.get(url) # this will download the image file\n",
429+
" file = open(f\"sample_data/locations-{place[0]}.jpg\", \"wb\") # create a filehandler and give path\n",
430+
" file.write(download.content) # write image content to filename\n",
431+
" file.close() # close filehandler"
432+
],
433+
"metadata": {
434+
"id": "o3ocl-Ro9WOG"
435+
},
436+
"execution_count": null,
437+
"outputs": []
438+
},
439+
{
440+
"cell_type": "markdown",
441+
"source": [
442+
"Try to replace the locations.csv file with coordinates that might be interesting for you to spot. Can you combine the dates and the locations into one big batch download?"
443+
],
444+
"metadata": {
445+
"id": "mJspCWE1HEeG"
446+
}
447+
},
448+
{
449+
"cell_type": "code",
450+
"source": [
451+
"# experiment here"
452+
],
453+
"metadata": {
454+
"id": "ItkoYVlcHQJg"
455+
},
456+
"execution_count": null,
457+
"outputs": []
458+
},
459+
{
460+
"cell_type": "markdown",
461+
"source": [
462+
"## Fetching satellite images with Google Maps API"
463+
],
464+
"metadata": {
465+
"id": "G7BpldHgHRbO"
466+
}
449467
}
450468
],
451469
"metadata": {

0 commit comments

Comments
 (0)
Please sign in to comment.