diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index fee20c4..9c52149 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -10,11 +10,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "id": "215eb6bc", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import pandas as pd\n", + "from pandas import json_normalize\n", + "\n", + "import requests \n", + "import json\n", + "import os\n", + "import time\n", + "\n", + "from datetime import datetime\n", + "\n", + "\n", + "\n", + "\n" + ] }, { "cell_type": "markdown", @@ -42,34 +56,27 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 25, "id": "8c147eb7", "metadata": {}, "outputs": [], "source": [ "# Your code here\n", - "# base_url" + "url = \"http://dog-api.kinduff.com\"\n" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 26, "id": "c503211c", "metadata": {}, "outputs": [], "source": [ "# Your code here\n", - "# endpoint " - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "e8563709", - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here" + "endpoint = \"/api/facts\"\n", + "\n", + "url_for_request = url + endpoint\n", + " \n" ] }, { @@ -82,12 +89,26 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 40, "id": "311d0c28", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'facts': ['The dog was frequently depicted in Greek art, including Cerberus, the three-headed hound guarding the entrance to the underworld, and the hunting dogs which accompanied the virgin goddess of the chase, Diana.'],\n", + " 'success': True}" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "res = requests.get(url_for_request)\n", + "res.json()" ] }, { @@ -110,12 +131,20 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 41, "id": "e7dc2129", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "# Your code here\n", + "\n", + "def request_dog_facts():\n", + " url = \"http://dog-api.kinduff.com\"\n", + " endpoint = \"/api/facts\"\n", + " url_for_request = url + endpoint\n", + " res = requests.get(url_for_request)\n", + " res.json()\n", + " return {}" ] }, { @@ -136,12 +165,35 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 68, "id": "9263e7c8", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'facts': ['There are hundreds of breeds of dogs.'], 'success': True}" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "def request_dog_facts():\n", + " url = \"http://dog-api.kinduff.com\"\n", + " endpoint = \"/api/facts\"\n", + " url_for_request = url + endpoint\n", + " try:\n", + " res = requests.get(url_for_request)\n", + " return res.json() \n", + " except:\n", + " print(\"Too many requests\")\n", + " \n", + "request_dog_facts()" ] }, { @@ -162,12 +214,16 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 69, "id": "1e7947fe", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "# Your code here\n", + "\n", + "current_date_time = datetime.now()\n", + "current_month = current_date_time.month\n", + "\n" ] }, { @@ -180,12 +236,42 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 70, "id": "731959ec", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[{'facts': ['Dogs have three eyelids. The third lid, called a nictitating membrane or \"haw,\" keeps the eye lubricated and protected.'],\n", + " 'success': True},\n", + " {'facts': ['Dogs are natural pack animals.'], 'success': True},\n", + " {'facts': ['Even with their poor eyesight, dogs can still see better at night than humans do.'],\n", + " 'success': True},\n", + " {'facts': ['Dogs are capable of understanding up to 250 words and gestures, can count up to five and can perform simple mathematical calculations. The average dog is as intelligent as a two-year-old child.'],\n", + " 'success': True},\n", + " {'facts': ['A dog’s powerful sense of smell is frequently called upon to detect anything from mines and explosives to termites and bed bugs.'],\n", + " 'success': True},\n", + " {'facts': ['Corgi is Welsh for \"dwarf dog\".'], 'success': True},\n", + " {'facts': ['Revolutionary War soldiers sometimes brought their dogs with them into battle. Such was the case with George Washington and his dog, Sweetlips.'],\n", + " 'success': True},\n", + " {'facts': ['Different smells in the a dog’s urine can tell other dogs whether the dog leaving the message is female or male, old or young, sick or healthy, happy or angry.'],\n", + " 'success': True},\n", + " {'facts': [\"President Lyndon Johnson's beagles were named Him and Her.\"],\n", + " 'success': True},\n", + " {'facts': ['One of the most famous Labrador Retrievers was \"Endal,\" an assistance dog recognized as the most decorated dog in the world.'],\n", + " 'success': True}]" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "ten_dogs_facts = [request_dog_facts() for _ in range(current_month)]\n", + "ten_dogs_facts" ] }, { @@ -198,12 +284,113 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 71, "id": "d22652ed", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
factssuccess
0[Dogs have three eyelids. The third lid, calle...True
1[Dogs are natural pack animals.]True
2[Even with their poor eyesight, dogs can still...True
3[Dogs are capable of understanding up to 250 w...True
4[A dog’s powerful sense of smell is frequently...True
5[Corgi is Welsh for \"dwarf dog\".]True
6[Revolutionary War soldiers sometimes brought ...True
7[Different smells in the a dog’s urine can tel...True
8[President Lyndon Johnson's beagles were named...True
9[One of the most famous Labrador Retrievers wa...True
\n", + "
" + ], + "text/plain": [ + " facts success\n", + "0 [Dogs have three eyelids. The third lid, calle... True\n", + "1 [Dogs are natural pack animals.] True\n", + "2 [Even with their poor eyesight, dogs can still... True\n", + "3 [Dogs are capable of understanding up to 250 w... True\n", + "4 [A dog’s powerful sense of smell is frequently... True\n", + "5 [Corgi is Welsh for \"dwarf dog\".] True\n", + "6 [Revolutionary War soldiers sometimes brought ... True\n", + "7 [Different smells in the a dog’s urine can tel... True\n", + "8 [President Lyndon Johnson's beagles were named... True\n", + "9 [One of the most famous Labrador Retrievers wa... True" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "df = pd.DataFrame(ten_dogs_facts)\n", + "df" ] }, {