Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 219 additions & 32 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
},
{
Expand All @@ -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()"
]
},
{
Expand All @@ -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 {}"
]
},
{
Expand All @@ -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()"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -198,12 +284,113 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 71,
"id": "d22652ed",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>facts</th>\n",
" <th>success</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>[Dogs have three eyelids. The third lid, calle...</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>[Dogs are natural pack animals.]</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>[Even with their poor eyesight, dogs can still...</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>[Dogs are capable of understanding up to 250 w...</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>[A dog’s powerful sense of smell is frequently...</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>[Corgi is Welsh for \"dwarf dog\".]</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>[Revolutionary War soldiers sometimes brought ...</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>[Different smells in the a dog’s urine can tel...</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>[President Lyndon Johnson's beagles were named...</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>[One of the most famous Labrador Retrievers wa...</td>\n",
" <td>True</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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"
]
},
{
Expand Down