diff --git a/data/facts_dogs.csv b/data/facts_dogs.csv new file mode 100644 index 0000000..c111fbf --- /dev/null +++ b/data/facts_dogs.csv @@ -0,0 +1,28 @@ +,facts,success +0,"The term ""dog days of summer"" was coined by the ancient Greeks and Romans to describe the hottest days of summer that coincided with the rising of the Dog Star, Sirius.",True +1,"Some studies believe that dogs started to be domesticated 33,000 years ago.",True +2,Dogs have been used since the 1700’s for therapy.,True +3,"Dogs judge objects first by their movement, then by their brightness, and lastly by their shape.",True +4,"The shape of a dog’s face suggests how long it will live. Dogs with sharp, pointed faces that look more like wolves typically live longer. Dogs with very flat faces, such as bulldogs, often have shorter lives.",True +5,"During the Middle Ages, Great Danes and Mastiffs were sometimes suited with armor and spiked collars to enter a battle or to defend supply caravans.",True +6,Puppies grow to half their body weight in the first four to five months!,True +7,Dogs’ only sweat glands are between their paw pads.,True +8,Dogs can count up to five and can perform simple mathematical calculations.,True +9,"Weird dog laws include allowing police offers in Palding, Ohio, to bite a dog to quiet it. In Ventura County, California, cats and dogs are not allowed to have sex without a permit.",True +10,Dogs are all direct descendants of wolves.,True +11,Dogs have no sense of time.,True +12,"The Golden Retriever, one of the most popular dog breeds, was first bred in Scotland in the mid 1800s.",True +13,"The Labrador Retriever is the #1 favorite breed in the U.S., Canada, and the U.K.",True +14,The breed Lundehune has 6 toes and can close its ears.,True +15,Dogs are all direct descendants of wolves.,True +16,President Calvin Coolidge owned at least a dozen dogs.,True +17,"Irish Wolfhounds, the tallest breed, are 30 to 35 inches tall.",True +18,Female dogs carry puppies for about nine weeks before birth.,True +19,"The American Kennel Club, the most influential dog club in the United States, was founded in 1884.",True +20,"It is a myth that dogs are color blind. They can actually see in color, just not as vividly as humans. It is akin to our vision at dusk.",True +21,The Russians trained dogs during WWII to run suicide missions with mines strapped to their backs.,True +22,"Chocolate contains a substance known as theobromine (similar to caffeine) which can kill dogs or, at the very least, make them violently ill.",True +23,If you want a dog to see things in a green background the best color is blue.,True +24,"Just like human fingerprints, no two dogs' nose prints are alike.",True +25,President Theodore Roosevelt's Bull Terrier Pete ripped the pants off French Ambassador Jules Jusserand.,True +26,Obesity is the top health problem among dogs.,True diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index fee20c4..7ea9227 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -10,11 +10,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "id": "215eb6bc", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import requests\n", + "import pandas as pd\n", + "from pandas import json_normalize\n", + "import json\n", + "from datetime import datetime\n", + "\n" + ] }, { "cell_type": "markdown", @@ -42,29 +49,30 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 8, "id": "8c147eb7", "metadata": {}, "outputs": [], - "source": [ - "# Your code here\n", - "# base_url" - ] + "source": [] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 44, "id": "c503211c", "metadata": {}, "outputs": [], "source": [ - "# Your code here\n", - "# endpoint " + "\n", + "base_url = 'http://dog-api.kinduff.com/'\n", + "endpoint = 'api/facts'\n", + "url_for_request = base_url+endpoint\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 45, "id": "e8563709", "metadata": {}, "outputs": [], @@ -82,12 +90,22 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 46, "id": "311d0c28", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'facts': ['Dogs judge objects first by their movement, then by their brightness, and lastly by their shape.'], 'success': True}\n" + ] + } + ], "source": [ - "# Your code here" + "res = requests.get(url_for_request)\n", + "content = (res.json())\n", + "print(content)" ] }, { @@ -110,12 +128,33 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 47, "id": "e7dc2129", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'facts': ['A person should never kick a dog facing him or her. Some dogs can bite 10 times before a human can respond.'],\n", + " 'success': True}" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "def request_dog_facts():\n", + " base_url = 'http://dog-api.kinduff.com/'\n", + " endpoint = 'api/facts'\n", + " url_for_request = base_url+endpoint\n", + " res = requests.get(url_for_request)\n", + " content = (res.json())\n", + " return content\n", + "\n", + "dict_dog = request_dog_facts()\n", + "dict_dog" ] }, { @@ -136,12 +175,37 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 48, "id": "9263e7c8", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'facts': ['Search and Rescue dog training begin as games played while puppies.'],\n", + " 'success': True}" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "def request_dog_facts():\n", + "\n", + " try: \n", + " base_url = 'http://dog-api.kinduff.com/'\n", + " endpoint = 'api/facts'\n", + " url_for_request = base_url+endpoint\n", + " res = requests.get(url_for_request)\n", + " content = (res.json())\n", + " return content\n", + " except:\n", + " print(\"An error has occurred with API\")\n", + "\n", + "dict_dog = request_dog_facts()\n", + "dict_dog" ] }, { @@ -162,12 +226,25 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 49, "id": "1e7947fe", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "\n", + "month = int(datetime.now().strftime(\"%m\"))\n", + "month" ] }, { @@ -180,12 +257,15 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 50, "id": "731959ec", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "todays_date = int(datetime.now().strftime(\"%d\"))\n", + "\n", + "list_dict = [request_dog_facts() for _ in range(todays_date)]\n", + "print(list_dict)" ] }, { @@ -198,12 +278,48 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "d22652ed", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " facts success\n", + "0 [The Chihuahua was named after the state in Me... True\n", + "1 [In Croatia, scientists discovered that lamppo... True\n", + "2 [An American Animal Hospital Association poll ... True\n", + "3 [Dachshunds were originally bred to fight badg... True\n", + "4 [No, it’s not just to make themselves look ado... True\n", + "5 [All dogs can be traced back 40 million years ... True\n", + "6 [A person should never kick a dog facing him o... True\n", + "7 [Dalmatian puppies are born completely white.] True\n", + "8 [A dog’s pregnancy lasts for approximately 60 ... True\n", + "9 [Dogs aren't colorblind but their eyes don't h... True\n", + "10 [Dogs can see in color, though they most likel... True\n", + "11 [The best age to bring a puppy home is 8 to 12... True\n", + "12 [President Theodore Roosevelt's Bull Terrier P... True\n", + "13 [Dogs do not have an appendix. Why haven’t hum... True\n", + "14 [Perky-eared dogs hear sounds better than flop... True\n", + "15 [Express yourself. Dogs’ ears are extremely ex... True\n", + "16 [There are nearly 14,000 animal shelters and r... True\n", + "17 [A dog can locate the source of a sound in 1/6... True\n", + "18 [When dogs copulate, it is very normal for the... True\n", + "19 [The Beatles song \"A day in the Life\" has an e... True\n", + "20 [Hollywood’s first and arguably best canine su... True\n", + "21 [U.S. Customs dogs \"Rocky\" and \"Barco\" were so... True\n", + "22 [The most popular dog breed in Canada, U.S., a... True\n", + "23 [Unlike cats, dogs are not exclusively carnivo... True\n", + "24 [Humans generally see better than dogs, but do... True\n", + "25 [The Norwegian Lundehund is the only dog with ... True\n", + "26 [Dog trainers in ancient China were held in hi... True\n" + ] + } + ], "source": [ - "# Your code here" + "df = pd.DataFrame(list_dict)\n", + "print(df)" ] }, { @@ -216,20 +332,231 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "b29f4826", "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", + " \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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
factssuccess
0The Chihuahua was named after the state in Mex...True
1In Croatia, scientists discovered that lamppos...True
2An American Animal Hospital Association poll f...True
3Dachshunds were originally bred to fight badgers.True
4No, it’s not just to make themselves look ador...True
5All dogs can be traced back 40 million years a...True
6A person should never kick a dog facing him or...True
7Dalmatian puppies are born completely white.True
8A dog’s pregnancy lasts for approximately 60 d...True
9Dogs aren't colorblind but their eyes don't ha...True
10Dogs can see in color, though they most likely...True
11The best age to bring a puppy home is 8 to 12 ...True
12President Theodore Roosevelt's Bull Terrier Pe...True
13Dogs do not have an appendix. Why haven’t huma...True
14Perky-eared dogs hear sounds better than flopp...True
15Express yourself. Dogs’ ears are extremely exp...True
16There are nearly 14,000 animal shelters and re...True
17A dog can locate the source of a sound in 1/60...True
18When dogs copulate, it is very normal for them...True
19The Beatles song \"A day in the Life\" has an ex...True
20Hollywood’s first and arguably best canine sup...True
21U.S. Customs dogs \"Rocky\" and \"Barco\" were so ...True
22The most popular dog breed in Canada, U.S., an...True
23Unlike cats, dogs are not exclusively carnivor...True
24Humans generally see better than dogs, but dog...True
25The Norwegian Lundehund is the only dog with s...True
26Dog trainers in ancient China were held in hig...True
\n", + "
" + ], + "text/plain": [ + " facts success\n", + "0 The Chihuahua was named after the state in Mex... True\n", + "1 In Croatia, scientists discovered that lamppos... True\n", + "2 An American Animal Hospital Association poll f... True\n", + "3 Dachshunds were originally bred to fight badgers. True\n", + "4 No, it’s not just to make themselves look ador... True\n", + "5 All dogs can be traced back 40 million years a... True\n", + "6 A person should never kick a dog facing him or... True\n", + "7 Dalmatian puppies are born completely white. True\n", + "8 A dog’s pregnancy lasts for approximately 60 d... True\n", + "9 Dogs aren't colorblind but their eyes don't ha... True\n", + "10 Dogs can see in color, though they most likely... True\n", + "11 The best age to bring a puppy home is 8 to 12 ... True\n", + "12 President Theodore Roosevelt's Bull Terrier Pe... True\n", + "13 Dogs do not have an appendix. Why haven’t huma... True\n", + "14 Perky-eared dogs hear sounds better than flopp... True\n", + "15 Express yourself. Dogs’ ears are extremely exp... True\n", + "16 There are nearly 14,000 animal shelters and re... True\n", + "17 A dog can locate the source of a sound in 1/60... True\n", + "18 When dogs copulate, it is very normal for them... True\n", + "19 The Beatles song \"A day in the Life\" has an ex... True\n", + "20 Hollywood’s first and arguably best canine sup... True\n", + "21 U.S. Customs dogs \"Rocky\" and \"Barco\" were so ... True\n", + "22 The most popular dog breed in Canada, U.S., an... True\n", + "23 Unlike cats, dogs are not exclusively carnivor... True\n", + "24 Humans generally see better than dogs, but dog... True\n", + "25 The Norwegian Lundehund is the only dog with s... True\n", + "26 Dog trainers in ancient China were held in hig... True" + ] + }, + "execution_count": 81, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "df[\"facts\"]= df[\"facts\"].apply(lambda x: x[0])\n", + "\n", + "df" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "1086c456", + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "id": "d3fb564c", "metadata": {}, "source": [ - "# Save the dataframe into the data folder. " + "# Save the dataframe into the data folder. " ] }, { @@ -242,20 +569,28 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": null, "id": "ca21a372", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "df.to_csv(\"../data/facts_dogs.csv\")" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee1743bc", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "ironhack", + "display_name": "base", "language": "python", - "name": "ironhack" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -267,7 +602,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.11.4" }, "nbTranslate": { "displayLangs": [