Practice Putting it All Together
Practice News API Project: Putting it all together!
In this next section, we will be going through the steps of putting together a simple Python application. You will get practice with several important things like:
- Creating a new project
- Setting up a virtual environment.
- Installing libraries and setting up project dependencies.
- Calling an API (and setting of the .env file)
- Practice prompting AI to write code for you.
- Debugging errors.
First, try going through the following steps. If you get stuck, refer to the video that we provide at the end of this section!
-
Create a new project folder where your project files will live.
-
Create a virtual python environment for your project, and activate it. [Concept: Virtual Env] Refer to the commands in this section on virtual environments.
-
Create a NewsAPI account so that you will (get the free version), website here. Save the API key on your computer. [Concept: API]
-
Ask Cursor to help you create a Python flask app that leverages the API. [Concept: AI Coding] For example a prompt might look like:
1. Can you help me build a flask app that leverages the newsapi. It should just have a button for the user to click that surfaces the top headlining articles. Here is the API documentation to use: @https://newsapi.org/docs/get-started.
- Cursor will have written code that requires you to install packages for your project. It updated the requirements.txt file, so all you have to do is run the project installation file:
[todo-add instructions here].
[Concept: Project environment and dependencies]
- As part of the code, it will extract out the API key and create .env file. If Cursor didnβt create this .env file, create it yourself and add your News API key. [Concept: .env file]
- Letβs launch our python app [Concept: launch application in terminal] and see if it works:
- To do this, run the following command in your Terminal:
Terminal window npm run dev- If the code is working properly, when you open up the local web address you should see a button and when you click the button, it should show the top news articles of the day.
- Letβs resolve any remaining errors. [Concept: debugging]
- Once you have that working, letβs use the python wordCloud and matplotlib library to create and visualize a wordcloud based on the top headlining articles returned:
Once all the articles are extracted, can you use the wordcloud library WordCloud and matplotlib to create a wordcloud of all the article text. Can you then put that wordcloud at the top of the page?
Note, installing the matplotlib library can take around 10 minutes to install!
- Resolve out any remaining errors. [Concept: debugging]
You can use the following video for reference if you get stuck during the practice exercise!