diff --git a/data/bible_texts.csv b/data/bible_texts.csv new file mode 100644 index 0000000..46473c3 --- /dev/null +++ b/data/bible_texts.csv @@ -0,0 +1,36 @@ +Name,Role,Book,Chapter,Verse,Texts +Adam,First Man,Genesis,1,1,"In the beginning, God created the heavens and the earth." +Eve,First Woman,Genesis,22,5,"Abraham said to his young men, “Stay here with the donkey. The boy and I will go yonder. We will worship, and come back to you.”" +Noah,Builder of the Ark,Genesis,12,10,"There was a famine in the land. Abram went down into Egypt to live as a foreigner there, for the famine was severe in the land." +Abraham,Father of Nations,Genesis,6,15,"This is how you shall make it. The length of the ship shall be three hundred cubits, its width fifty cubits, and its height thirty cubits." +Sarah,Wife of Abraham,Genesis,28,2,"Arise, go to Paddan Aram, to the house of Bethuel your mother’s father. Take a wife from there from the daughters of Laban, your mother’s brother." +Moses,Leader of the Exodus,Exodus,2,3,"When she could no longer hide him, she took a papyrus basket for him, and coated it with tar and with pitch. She put the child in it, and laid it in the reeds by the river’s bank." +Aaron,Brother of Moses,Exodus,13,8,"You shall tell your son in that day, saying, ‘It is because of that which Yahweh did for me when I came out of Egypt.’" +David,King of Israel,1 Samuel,8,4,Then all the elders of Israel gathered themselves together and came to Samuel to Ramah. +Solomon,Wisest Man,Proverbs,12,9,"Better is he who is little know, and has a servant, +than he who honors himself, and lacks bread." +Isaiah,Prophet,Isaiah,4,6,"There will be a pavilion for a shade in the daytime from the heat, and for a refuge and for a shelter from storm and from rain." +Jeremiah,Prophet,Jeremiah,3,16,"It will come to pass, when you are multiplied and increased in the land, in those days,” says Yahweh, “they will no longer say, ‘the ark of Yahweh’s covenant!’ It will not come to mind. They won’t remember it. They won’t miss it, nor will another be made." +John the Baptist,Forerunner of Jesus,Matthew,12,5,"Or have you not read in the law, that on the Sabbath day, the priests in the temple profane the Sabbath, and are guiltless?" +Jesus Christ,Son of God,Matthew,5,10,"Blessed are those who have been persecuted for righteousness’ sake, + +for theirs is the Kingdom of Heaven." +Mary,Mother of Jesus,Luke,6,15,"Matthew; Thomas; James, the son of Alphaeus; Simon, who was called the Zealot;" +Peter,Apostle,Matthew,4,2,"When he had fasted forty days and forty nights, he was hungry afterward." +Andrew,Apostle,Matthew,3,3,"For this is he who was spoken of by Isaiah the prophet, saying, +“The voice of one crying in the wilderness, +make ready the way of the Lord. +Make his paths straight.”" +James the Greater,Apostle,Matthew,5,8,"Blessed are the pure in heart, +for they shall see God." +John the Evangelist,Apostle,John,3,4,"Nicodemus said to him, “How can a man be born when he is old? Can he enter a second time into his mother’s womb, and be born?”" +Philip,Apostle,Matthew,6,9,"Pray like this: ‘Our Father in heaven, may your name be kept holy." +Thomas,Apostle,Matthew,4,6,"and said to him, “If you are the Son of God, throw yourself down, for it is written, ‘He will put his angels in charge of you.’ and, +‘On their hands they will bear you up, +so that you don’t dash your foot against a stone.’”" +James the Lesser,Apostle,Matthew,18,9,"If your eye causes you to stumble, pluck it out, and cast it from you. It is better for you to enter into life with one eye, rather than having two eyes to be cast into the Gehenna +of fire." +Jude Thaddeus,Apostle,Matthew,9,12,"When Jesus heard it, he said to them, +“Those who are healthy have no need for a physician, but those who are sick do." +Simon the Zealot,Apostle,Matthew,27,3,"Then Judas, who betrayed him, when he saw that Jesus was condemned, felt remorse, and brought back the thirty pieces of silver to the chief priests and elders," +Bartholomew,Apostle,Matthew,6,2,"Therefore when you do merciful deeds, don’t sound a trumpet before yourself, as the hypocrites do in the synagogues and in the streets, that they may get glory from men. Most certainly I tell you, they have received their reward." diff --git a/data/doggies.csv b/data/doggies.csv new file mode 100644 index 0000000..88d51bb --- /dev/null +++ b/data/doggies.csv @@ -0,0 +1,29 @@ +facts,success +"Dogs judge objects first by their movement, then by their brightness, and lastly by their shape.",True +"Two Labradors, Lucky and Flo, were the first dogs known for sniffing out pirated DVDs.",True +"Flyball, a dog sport consisting of relays, hurdles, and ball retrieving, was developed in the late 60s, and the first tournament was held in 1983.",True +"According to a study shared by Cornell University, dogs were domesticated between 9,000 and 34,000 years ago.",True +Dogs are all direct descendants of wolves.,True +Dachshunds were originally bred for fighting badgers.,True +Petting a dog can lower your blood pressure.,True +"In Iran, it is against the law to own a dog as a pet. However, if an owner can prove the dog is a guard or hunting dog, this restriction doesn’t apply. Muslim reticence concerning dogs is perhaps due to the fact that rabies has always been endemic in the Middle East.",True +"The Beagle and Collie are the nosiest dogs, while the Akbash Dog and the Basenji are the quietest.",True +"The earliest dog fossil dates back to nearly 10,000 B.C.",True +Toto in The Wizard of Oz was played by a female Cairn Terrier named Terry.,True +"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.",True +"The fastest breed, the Greyhound, can run up to 44 miles per hour.",True +The most popular male dog names are Max and Jake. The most popular female dog names are Maggie and Molly.,True +"Revolutionary War soldiers sometimes brought their dogs with them into battle. Such was the case with George Washington and his dog, Sweetlips.",True +"Dogs engage in rapid-eye-movement when they sleep, and have dreams just like humans do.",True +Mastiffs wore armor and were sent after mounted knights in Roman times.,True +"Humans can detect sounds at 20,000 times per second, while dogs can sense frequencies of 30,000 times per second.",True +"There are nearly 14,000 animal shelters and rescue groups across North America.",True +The average dog is as intelligent as a two-year-old child.,True +Dogs often bury bones so that they can dig them up at some moment in the future when they are hungry.,True +"An elderly woman was saved by her 12-pound Yorkshire Terrier, who fought off an 80- pound Akita, and survived with only 9 stitches.",True +"Dog’s definitely don’t see like hawks. They have very poor eyesight, but can distinguish movement 10-20 times better than humans.",True +Many foot disorders in dogs are simply an issue of too-long toenails.,True +More than half of all U.S. presidents have owned dogs.,True +Your pup reaches his full size between 12 and 24 months.,True +"Female dogs are only ready to mate–""in heat""–twice a year for a total of roughly 20 days.",True +Many foot disorders in dogs are caused by long toenails.,True diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index fee20c4..f3e184c 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -10,11 +10,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "215eb6bc", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "import pandas as pd\n", + "import requests \n", + "import json\n", + "import datetime" + ] }, { "cell_type": "markdown", @@ -47,29 +52,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here\n", - "# base_url" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "c503211c", - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n", - "# endpoint " - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "e8563709", - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here" + "base_url = \"https://dog-api.kinduff.com\"\n", + "endpoint = \"/api/facts\"\n", + "url_for_request = base_url + endpoint" ] }, { @@ -82,12 +67,25 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 3, "id": "311d0c28", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'facts': [\"Service dogs are trained to know when they are on duty. When their harness is on, they know it's business time. When you take it off, the pups immediately become playful and energetic.\"],\n", + " 'success': True}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "res = requests.get(url_for_request).json()\n", + "res" ] }, { @@ -110,12 +108,15 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 4, "id": "e7dc2129", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "def request_dog_facts():\n", + " for i in range (10):\n", + " res = requests.get(\"https://dog-api.kinduff.com/api/facts\").json()\n", + " print(res)" ] }, { @@ -136,12 +137,18 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "id": "9263e7c8", "metadata": {}, "outputs": [], "source": [ - "# your code here" + "def request_dog_facts():\n", + " try:\n", + " for i in range (10):\n", + " res = requests.get(\"https://dog-api.kinduff.com/api/facts\").json()\n", + " print(res)\n", + " except:\n", + " print(\"Requested too many times\")" ] }, { @@ -162,12 +169,20 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "id": "1e7947fe", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "def request_dog_facts():\n", + " dict_ = []\n", + " current_month = int(datetime.datetime.now().strftime(\"%m\"))\n", + " try:\n", + " for i in range (current_month):\n", + " res = requests.get(\"https://dog-api.kinduff.com/api/facts\").json()\n", + " except:\n", + " print(\"Requested too many times\")\n", + " return res" ] }, { @@ -180,12 +195,15 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "id": "731959ec", - "metadata": {}, + "metadata": { + "scrolled": true + }, "outputs": [], "source": [ - "# Your code here" + "todays_date = int(datetime.datetime.now().strftime(\"%d\"))\n", + "dogs_facts = [request_dog_facts() for i in range (todays_date)]" ] }, { @@ -198,12 +216,12 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "id": "d22652ed", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "df = pd.DataFrame(dogs_facts)" ] }, { @@ -216,12 +234,12 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "id": "b29f4826", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "df[\"facts\"] = df[\"facts\"].apply(lambda x: \"\".join(x))" ] }, { @@ -242,12 +260,12 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 10, "id": "ca21a372", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "df.to_csv('../data/doggies.csv', index=False)" ] } ], diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index a573e5f..e844754 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -50,12 +50,15 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 1, "id": "215eb6bc", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "import pandas as pd\n", + "import requests\n", + "import json\n", + "import datetime" ] }, { @@ -76,12 +79,12 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 13, "id": "6ba76753", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "df = pd.read_csv(\"../data/bible.csv\")" ] }, { @@ -110,12 +113,36 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 14, "id": "8ab21dfb", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'reference': 'John 3:16',\n", + " 'verses': [{'book_id': 'JHN',\n", + " 'book_name': 'John',\n", + " 'chapter': 3,\n", + " 'verse': 16,\n", + " 'text': '\\nFor God so loved the world, that he gave his one and only Son, that whoever believes in him should not perish, but have eternal life.\\n\\n'}],\n", + " 'text': '\\nFor God so loved the world, that he gave his one and only Son, that whoever believes in him should not perish, but have eternal life.\\n\\n',\n", + " 'translation_id': 'web',\n", + " 'translation_name': 'World English Bible',\n", + " 'translation_note': 'Public Domain'}" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "base_url = \"https://bible-api.com\"\n", + "endpoint = \"/john 3:16\"\n", + "url_for_request = base_url + endpoint\n", + "res = requests.get(url_for_request).json()\n", + "res" ] }, { @@ -128,12 +155,24 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 15, "id": "5ac1bcd2", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'For God so loved the world, that he gave his one and only Son, that whoever believes in him should not perish, but have eternal life.'" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "text = res[\"text\"].strip()\n", + "text" ] }, { @@ -154,12 +193,379 @@ }, { "cell_type": "code", - "execution_count": 6, - "id": "b3a9a0f0", + "execution_count": 16, + "id": "753bd271", "metadata": {}, "outputs": [], "source": [ - "# Your code here" + "# I understood the exercise as creating a function to get the text given a book, chapter and verse:\n", + "def getText(book, chapter, verse):\n", + " df[\"Nueva_columna\"] = df[\"Book\"] + \" \" + df[\"Chapter\"].apply(lambda x: str(x)) + \":\" + df[\"Verse\"].apply(lambda x: str(x))\n", + " endpointdf = pd.Series(df[\"Nueva_columna\"].loc[(df[\"Book\"] == book) & (df[\"Chapter\"] == chapter) & (df[\"Verse\"] == verse)])\n", + " df.drop(\"Nueva_columna\", axis=1, inplace=True)\n", + " endpoint = \"/\" + endpointdf.values[0]\n", + " url_for_request = \"https://bible-api.com\" + endpoint\n", + " res = requests.get(url_for_request).json()\n", + " text = res[\"text\"].strip()\n", + " return text" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "8c018c77", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Blessed are those who have been persecuted for righteousness’ sake,\\n\\nfor theirs is the Kingdom of Heaven.'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "getText(\"Matthew\", 5, 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "1271ad84", + "metadata": {}, + "outputs": [], + "source": [ + "# As later it asks to save a dataframe, I create a new column with given texts:\n", + "\n", + "# I tried the following loop, also tried looping manually. Sometimes it works, I think that the errors arising had to do\n", + "# with the time response?\n", + "\n", + "for i in range(df.shape[0]):\n", + " df.loc[i, \"Texts\"] = getText(df.loc[i, \"Book\"], df.loc[i, \"Chapter\"], df.loc[i, \"Verse\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "bfc9f5bd", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/html": [ + "
| \n", + " | Name | \n", + "Role | \n", + "Book | \n", + "Chapter | \n", + "Verse | \n", + "Texts | \n", + "
|---|---|---|---|---|---|---|
| 0 | \n", + "Adam | \n", + "First Man | \n", + "Genesis | \n", + "1 | \n", + "1 | \n", + "In the beginning, God created the heavens and ... | \n", + "
| 1 | \n", + "Eve | \n", + "First Woman | \n", + "Genesis | \n", + "22 | \n", + "5 | \n", + "Abraham said to his young men, “Stay here with... | \n", + "
| 2 | \n", + "Noah | \n", + "Builder of the Ark | \n", + "Genesis | \n", + "12 | \n", + "10 | \n", + "There was a famine in the land. Abram went dow... | \n", + "
| 3 | \n", + "Abraham | \n", + "Father of Nations | \n", + "Genesis | \n", + "6 | \n", + "15 | \n", + "This is how you shall make it. The length of t... | \n", + "
| 4 | \n", + "Sarah | \n", + "Wife of Abraham | \n", + "Genesis | \n", + "28 | \n", + "2 | \n", + "Arise, go to Paddan Aram, to the house of Beth... | \n", + "
| 5 | \n", + "Moses | \n", + "Leader of the Exodus | \n", + "Exodus | \n", + "2 | \n", + "3 | \n", + "When she could no longer hide him, she took a ... | \n", + "
| 6 | \n", + "Aaron | \n", + "Brother of Moses | \n", + "Exodus | \n", + "13 | \n", + "8 | \n", + "You shall tell your son in that day, saying, ‘... | \n", + "
| 7 | \n", + "David | \n", + "King of Israel | \n", + "1 Samuel | \n", + "8 | \n", + "4 | \n", + "Then all the elders of Israel gathered themsel... | \n", + "
| 8 | \n", + "Solomon | \n", + "Wisest Man | \n", + "Proverbs | \n", + "12 | \n", + "9 | \n", + "Better is he who is little know, and has a ser... | \n", + "
| 9 | \n", + "Isaiah | \n", + "Prophet | \n", + "Isaiah | \n", + "4 | \n", + "6 | \n", + "There will be a pavilion for a shade in the da... | \n", + "
| 10 | \n", + "Jeremiah | \n", + "Prophet | \n", + "Jeremiah | \n", + "3 | \n", + "16 | \n", + "It will come to pass, when you are multiplied ... | \n", + "
| 11 | \n", + "John the Baptist | \n", + "Forerunner of Jesus | \n", + "Matthew | \n", + "12 | \n", + "5 | \n", + "Or have you not read in the law, that on the S... | \n", + "
| 12 | \n", + "Jesus Christ | \n", + "Son of God | \n", + "Matthew | \n", + "5 | \n", + "10 | \n", + "Blessed are those who have been persecuted for... | \n", + "
| 13 | \n", + "Mary | \n", + "Mother of Jesus | \n", + "Luke | \n", + "6 | \n", + "15 | \n", + "Matthew; Thomas; James, the son of Alphaeus; S... | \n", + "
| 14 | \n", + "Peter | \n", + "Apostle | \n", + "Matthew | \n", + "4 | \n", + "2 | \n", + "When he had fasted forty days and forty nights... | \n", + "
| 15 | \n", + "Andrew | \n", + "Apostle | \n", + "Matthew | \n", + "3 | \n", + "3 | \n", + "For this is he who was spoken of by Isaiah the... | \n", + "
| 16 | \n", + "James the Greater | \n", + "Apostle | \n", + "Matthew | \n", + "5 | \n", + "8 | \n", + "Blessed are the pure in heart,\\nfor they shall... | \n", + "
| 17 | \n", + "John the Evangelist | \n", + "Apostle | \n", + "John | \n", + "3 | \n", + "4 | \n", + "Nicodemus said to him, “How can a man be born ... | \n", + "
| 18 | \n", + "Philip | \n", + "Apostle | \n", + "Matthew | \n", + "6 | \n", + "9 | \n", + "Pray like this: ‘Our Father in heaven, may you... | \n", + "
| 19 | \n", + "Thomas | \n", + "Apostle | \n", + "Matthew | \n", + "4 | \n", + "6 | \n", + "and said to him, “If you are the Son of God, t... | \n", + "
| 20 | \n", + "James the Lesser | \n", + "Apostle | \n", + "Matthew | \n", + "18 | \n", + "9 | \n", + "If your eye causes you to stumble, pluck it ou... | \n", + "
| 21 | \n", + "Jude Thaddeus | \n", + "Apostle | \n", + "Matthew | \n", + "9 | \n", + "12 | \n", + "When Jesus heard it, he said to them,\\n“Those ... | \n", + "
| 22 | \n", + "Simon the Zealot | \n", + "Apostle | \n", + "Matthew | \n", + "27 | \n", + "3 | \n", + "Then Judas, who betrayed him, when he saw that... | \n", + "
| 23 | \n", + "Bartholomew | \n", + "Apostle | \n", + "Matthew | \n", + "6 | \n", + "2 | \n", + "Therefore when you do merciful deeds, don’t so... | \n", + "