Using a text file with JSON data and use it in Tkinter

Viewed 225

I have used an API using python, to call out to "NewsAPI" to get all the latest news that I need and I have actually save it into a text file called "NewsAPI.txt".

My code is:

    import json 
    import requests


    def newsAPI():
        url = ('https://newsapi.org/v2/everything?' #API URL
               'q=procurement AND tender&' #keywords on procurement AND tender
               'sortBy=popularity&' #Sort them by popularity
               'apiKey=***') #Personal API key

        # GET
        response = requests.get(url)

        #storing the output into variable "results"
        results = response.json()
        # save the JSON output into a txt file for future usage
        with open("NewsAPI.txt", "w") as text_file:
            json.dump(results, text_file)

After calling json.dump, it gets saved into the "NewsAPI.txt" file as I have mentioned. But I'm having trouble putting it into a treeview in Tkinter, or am I using the wrong widget to display them?

Output data: Output for the JSON DATA

0 Answers
Related