(If anyone can help me solve this to understand better, it'll be helpful. Using python with knowledge...
Question:
(If anyone can help me solve this to understand better, it'll be helpful. Using python with knowledge of some flask) Thanks
#TODO: instance of a Flask web app and call it app
app.config['SECRET_KEY']=os.urandom(16).hex()
""" ----------- I - JSON DOCUMENTS ----------- """
def save_to_file(data,filename):
with open(filename,'w') as write_file:
json.dump(data,write_file,indent=2)
def read_from_file(filename):
with open(filename,'r') as read_file:
data = json.load(read_file)
return data
""" ----------- 2 - API KEY ----------- """
#TODO: read from the api_key.json file and assign your API key to a variable named api_key
""" ----------- 3 - USEFUL LISTS ----------- """
#TODO: read from the countries.json file and assign its value to a variable named countries
countries_list = list(countries.keys()) #this line of code is done for you, it creates a list containing all the country names
#variable charts is done for you, it provides a list of possible chart names for the user to select from
charts = [("top", "Editorial Chart"),
("hot", "Most viewed lyrics in the last 2 hours"),
("mxmweekly", "Most viewed lyrics in the last 7 days"),
("mxmweekly_new", "Most viewed lyrics in the last 7 days limited to new releases only")]
#variable number of results is done for you, it provides 4 options for the user to select from
number_of_results = [5,10,15,20]
""" ----------- FORMS ----------- """
#TODO: define a class named Search and include 3 input fields:
# - select field named country
# - select field named chartType
# - integer field named numberResults (let the user only enter an integer from 1 to 10)
""" ----------- API CALLS ----------- """
#TODO: this function definition by filling out the missing:
# - input arguments of the function
# - the API request to the defined url
# - saving the response of the API request to file
# - returning the response of the API request
def request_top_artists(???):
top_artists_url="https://api.musixmatch.com/ws/1.1/chart.artists.get?country={0}&page_size={1}&apikey={2}"\
.format(country_code, number_of_results, api_key)
???
???
???
# TODO: this function definition by filling out the missing:
# - input arguments of the function
# - the API request to the defined url
# - saving the response of the API request to file
# - returning the response of the API request
def request_top_tracks():
top_tracks_url="https://api.musixmatch.com/ws/1.1/chart.tracks.get?country={0}&chart_name={1}&page_size={2}&apikey={3}"\
.format(country_code,chart_name, number_of_results, api_key)
???
???
???
""" ----------- ROUTES ----------- """
#TODO: finish index() function by:
# - assigning the Search form into a variable named form
# - getting the input data from the user for the fields:
# - country
# - chartType
# - numberResults
# - iterate over the artist list inside the top_artists variable
# and append the artist names to the list list_of_artists
# - iterate over the track list inside the top_track variable
# and append the track names, artist names, and share urls to the list l..;@app.route('/', methods=["GET","POST"])
def index():
???
if request.method == "POST":
???
???
???
""" TOP ARTISTS PER COUNTRY """
top_artists = request_top_artists(countries[countrySelected],numberResults)
list_of_artists = []
???
???
""" TOP TRACKS PER COUNTRY AND CHART"""
top_tracks = request_top_tracks(countries[countrySelected], chartSelected,numberResults)
list_of_tracks = []
???
???
return render_template('results.html', list_of_artists=list_of_artists, list_of_tracks=list_of_tracks,
country=countrySelected, quantity=numberResults)
return render_template('index.html', form=form)
if __name__ == '__main__':
app.run(port=5050,debug=True)
Cost Accounting Foundations and Evolutions
ISBN: 978-1111626822
8th Edition
Authors: Michael R. Kinney, Cecily A. Raiborn