This repository contains a simple Flask web application that interfaces with a MongoDB backend to display and search news articles.
-
app.py:
- Sets up the Flask web application.
- Connects to the MongoDB
dbbonmedia
database. - Defines routes for the main page (
/
), listing all news articles (/api/list
), and searching articles based on user input (/search
).
-
init_db.py:
- Utilizes
newsapi
to fetch articles related to 'crypto' and 'web3'. - Inserts the fetched articles into the MongoDB
news
collection. - Before insertion, it clears out the existing data in the
news
collection.
- Utilizes
- Ensure MongoDB is running and accessible on
localhost:27017
. - Install necessary Python libraries:
pip install Flask pymongo newsapi-python
- Run
init_db.py
to fetch the latest news articles and populate the MongoDB database.python init_db.py
- Run
app.py
to start the Flask web application.python app.py
- Display all news articles from the MongoDB
news
collection on the main page. - Search functionality to filter articles based on user input.