Question
Hi, this is my lab, and it is pretty long. I separate the lab into three chegg questions(they are connected). This is the second part.
Hi, this is my lab, and it is pretty long. I separate the lab into three chegg questions(they are connected). This is the second part. Please help me with them! Please see my last post, since it contains the first part and all the explanations and instructions. Please read them carefully and follow the instructions.
Those are the URL.
Books
You can request data for a particular book (here we are requesting information for the book with ID 1):
http://www.anapioficeandfire.com/api/books/1
You can request to get a list of all the book data:
http://www.anapioficeandfire.com/api/books
Or you can filter the list of books by name or date. For example:
http://www.anapioficeandfire.com/api/books?name=A Dance with Dragons
Characters
Similarly you can request data for a particular character (here we are requesting information for the character with id 823):
http://www.anapioficeandfire.com/api/characters/823
You can request to get a list of all the data objects for all the characters:
http://www.anapioficeandfire.com/api/characters
Or you can filter the list by many different fields including name, gender, culture, year of birth or death, or if the character is still alive. For Example:
http://www.anapioficeandfire.com/api/characters?name=Eddard Stark
Houses
Finally, you can get information about houses (for those who arent familiar with the shows/books - houses is the series name for dynastic families.). A single house:
http://www.anapioficeandfire.com/api/houses/362
A list of all houses:
http://www.anapioficeandfire.com/api/houses
Or you may filter the list of houses by many criteria. For example:
http://www.anapioficeandfire.com/api/houses?region=The North
For information on all the queries you can make and how to interpret the data returned see the API of Fire and Ice Documentation starting with the section on books.
The lab is continuing(the rest are in the following posts)...please help me! Thank you very much!?
Optional Arguments Python allows for optional arguments. You have used optional arguments before, probably without thinking about it. For example, range can have one, two, or three arguments. That is because the second and third arguments are optionals. To create an optional argument, you assign the argument a default value in the function declaration. For example: def adder(x, y-l): return xy In his example y s an optional a argument (as norma): ument you call adder with only one argument y s assigned the default vale ? but if you cal tw w arguments y sa signed th aueo the second adder(10, 20) 30 ss adder(18) Make getGOTObjects second argument an optional argument. If the function is called with one argument then filterParaneter should be assigned the empty string as a value. Dealing with Pages, Politely To download all the pages for a given query, and merge them all into a single list, getGoTobjects needs to repeatedly request successive pages. There are two different approaches you can take to solve this problem. 1. For each request, you can find the next link in the header and request that page. You can continue doing this until you download a page without a next link. If you use this approach, I suggest you write a function that takes a string formatted like the link value and returns the next URL 2. Or, you can analyze the link value in header from the first page. From the initial link value, you can see how many pages need to be requested and how to request a given page. You can then repeatedly requests pages starting with page two and ending with the last page. If you use this approach, I suggest you write a function that takes a string formatted like the link value and returns the last page number. Regardless of the approach, you take you need to request pages repeatedly. Many APl's have a "rate limit" which controls how many requests you can make in a given amount of time. For example, Instagram allows 5000 requests per hour. The API of Ice and Fire doesn't have a strict rate limit but it is still considered impolite to make too many requests in too short of a time (this is especially true in this class were many of you will be testing your functions at the same time) We don't want to tax their servers too badly so we will introduce a 1/10 of a second delay into our functions. In python, if you want your program to pause you can use the sleep method. Defined in the tine module. inport time a the top of your module. Then, after your call to request.get add the line tine.sleep(.1) This will slow down your program so that you never make more than 10 requests in a second (it also means that, depending on the query) you may need to wait a couple of minutes to get a result. The API of Ice and Fire does limit the number of requests that are allowed in a 24 hour period to 20000 requests. Unless you have a bug in your function, it is unlikely you'l hit this limit. You may want to add a print statement that shows the text of each URL that is being requested. That way, you'll know if you are repeatedly requesting the wrong URLs without having to wait until your function exits. Optional Arguments Python allows for optional arguments. You have used optional arguments before, probably without thinking about it. For example, range can have one, two, or three arguments. That is because the second and third arguments are optionals. To create an optional argument, you assign the argument a default value in the function declaration. For example: def adder(x, y-l): return xy In his example y s an optional a argument (as norma): ument you call adder with only one argument y s assigned the default vale ? but if you cal tw w arguments y sa signed th aueo the second adder(10, 20) 30 ss adder(18) Make getGOTObjects second argument an optional argument. If the function is called with one argument then filterParaneter should be assigned the empty string as a value. Dealing with Pages, Politely To download all the pages for a given query, and merge them all into a single list, getGoTobjects needs to repeatedly request successive pages. There are two different approaches you can take to solve this problem. 1. For each request, you can find the next link in the header and request that page. You can continue doing this until you download a page without a next link. If you use this approach, I suggest you write a function that takes a string formatted like the link value and returns the next URL 2. Or, you can analyze the link value in header from the first page. From the initial link value, you can see how many pages need to be requested and how to request a given page. You can then repeatedly requests pages starting with page two and ending with the last page. If you use this approach, I suggest you write a function that takes a string formatted like the link value and returns the last page number. Regardless of the approach, you take you need to request pages repeatedly. Many APl's have a "rate limit" which controls how many requests you can make in a given amount of time. For example, Instagram allows 5000 requests per hour. The API of Ice and Fire doesn't have a strict rate limit but it is still considered impolite to make too many requests in too short of a time (this is especially true in this class were many of you will be testing your functions at the same time) We don't want to tax their servers too badly so we will introduce a 1/10 of a second delay into our functions. In python, if you want your program to pause you can use the sleep method. Defined in the tine module. inport time a the top of your module. Then, after your call to request.get add the line tine.sleep(.1) This will slow down your program so that you never make more than 10 requests in a second (it also means that, depending on the query) you may need to wait a couple of minutes to get a result. The API of Ice and Fire does limit the number of requests that are allowed in a 24 hour period to 20000 requests. Unless you have a bug in your function, it is unlikely you'l hit this limit. You may want to add a print statement that shows the text of each URL that is being requested. That way, you'll know if you are repeatedly requesting the wrong URLs without having to wait until your function exitsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started