示例#1
0
def generateDataFromAPI(keyword, order_By, critics_Picks):
    my_key_dict = main_functions.read_from_file(
        "Project2_Flask/JSON_Documents/api_keys.json")
    my_key = my_key_dict["my_ny_key"]
    url = "https://api.nytimes.com/svc/movies/v2/reviews/search.json?query=" + keyword + "&order=" + order_By + "&critics-pick=" + critics_Picks + "&api-key=" + my_key
    response = requests.get(url).json()
    main_functions.save_to_file(response,
                                "Project2_Flask/JSON_Documents/response.json")
    response_dict = main_functions.read_from_file(
        "Project2_Flask/JSON_Documents/response.json")
    data_requested = {}
    movieTitles = []
    for i in response_dict["results"]:
        movieTitles.append(i["display_title"])
    critics = []
    for i in response_dict["results"]:
        critics.append(i["byline"])
    publicationDates = []
    for i in response_dict["results"]:
        publicationDates.append(i["publication_date"])
    reviewUrls = []
    for i in response_dict["results"]:
        reviewUrls.append(i["link"]["url"])
    """From the response dictionary, you need to filter the data requested by the user"""
    data_requested["titles"] = movieTitles
    data_requested["critics"] = critics
    data_requested["publicationDates"] = publicationDates
    data_requested["reviewLinks"] = reviewUrls
    return data_requested
示例#2
0
def search():
    my_form = forms.NewsForm(request.form)

    if request.method == 'POST':
        first_name = request.form["first_name"]
        date = request.form["date"]
        list_name = request.form["list_name"]

        # Couldn't figure out how to run this from forms :/ sorry
        url = "https://api.nytimes.com/svc/books/v3/lists/" + date + "/" + list_name + ".json?api-key="
        final_url = url + api_key
        response_ = requests.get(final_url).json()
        main_functions.save_to_file(response_,
                                    "Project2_Flask/JSON_Files/response.json")
        data = main_functions.read_from_file(
            "Project2_Flask/JSON_Files/response.json")

        book1 = data['results']['books'][0]['title']
        book2 = data['results']['books'][1]['title']
        book3 = data['results']['books'][2]['title']
        book4 = data['results']['books'][3]['title']
        book5 = data['results']['books'][4]['title']

        response = [first_name, book1, book2, book3, book4, book5]

        return render_template('results.html', response=response, form=my_form)
    return render_template('search.html', form=my_form)
示例#3
0
def generateDataFromAPI():

    url = "https://api.nytimes.com/svc/books/v3/lists/" + date + "/" + list_name + ".json"
    final_url = url + api_key
    response = requests.get(final_url).json()
    main_functions.save_to_file(response,
                                "Project2_Flask/JSON_Files/response.json")
    response_dict = main_functions.read_from_file(
        "Project2_Flask/JSON_Files/response.json")
示例#4
0
def generateDataFromAPI():
    my_key_dict = main_functions.read_from_file(
        "Project2_Flask/JSON_Files/api_key.json")
    my_key = my_key_dict["my_key"]
    url = "https://api.nytimes.com/svc/books/v3/lists/best-sellers/history.json?api-key=" + my_key
    response = requests.get(url).json()
    main_functions.save_to_file(response,
                                "Project2_Flask/JSON_Files/response.json")
    bestselling_books = main_functions.read_from_file(
        "Project2_Flask/JSON_Files/response.json")
    print(bestselling_books.get("status"))

    # find out if a book is best selling
    data_requested = bestselling_books

    return data_requested
示例#5
0
文件: forms.py 项目: The-HM/Project2
def movie_search(title, order, critics_picks):
    api_key_dict = main_functions.read_from_file(
        "Project2_Flask/JSON_Documents/api_keys.json")
    api_key = api_key_dict["my_ny_key"]

    url = "https://api.nytimes.com/svc/movies/v2/reviews/search.json?query=" + title + "&" + "critics-pick=" + critics_picks + "&" + "order=" + order + ";" + "&api-key=" + api_key

    response = requests.get(url).json()
    "https://api.nytimes.com/svc/movies/v2/reviews/search.json?query=godfather&api-key=yourkey"
    main_functions.save_to_file(response,
                                "Project2_Flask/JSON_Documents/response.json")

    response_dict = main_functions.read_from_file(
        "Project2_Flask/JSON_Documents/response.json")
    print(url)
    return response_dict
示例#6
0
def generateDataFromAPI(self):
    url = "https://api.nytimes.com/svc/books/v3/reviews.json?author="
    my_key_dict = main_functions.read_from_file(
        "Project2_Flask/JSON_Files/api_keys.json")
    my_key = my_key_dict["my_api_key"]

    if NewsForm.author == "Haruki Murakami":
        user_author = "Haruki+Murakami"
    elif NewsForm.author == "Yukio Mishima":
        user_author = "Yukio+Mishima"
    elif NewsForm.author == "Kazuo Ishiguro":
        user_author = "Kazuo+Ishiguro"
    else:
        user_author = "Junichirō+Tanizaki"

    # Final URL
    final_url = url + user_author + "&api-key=" + my_key
    """Maybe you need to provide extra information in the API url"""
    response = requests.get(final_url).json()

    # Save info to response.json
    main_functions.save_to_file(response,
                                "Project2_Flask/JSON_Files/response.json")
    """From the response dictionary, you need to filter the data requested by the user"""
    my_books = main_functions.read_from_file(
        "Project2_Flask/JSON_Files/response.json")

    book_t = response.json()['results']

    book_title = []

    for b in book_t:
        title = b['book_title']
        book_title.append(title)

    return book_title