Skip to content

Commit

Permalink
add feature:delete the previous data from mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsnoopy committed Oct 21, 2024
1 parent 74c4b62 commit db3e5d4
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 4 deletions.
Binary file modified app/__pycache__/routes.cpython-311.pyc
Binary file not shown.
Binary file modified app/__pycache__/rss_to_json.cpython-311.pyc
Binary file not shown.
Binary file modified app/__pycache__/rss_to_json.cpython-312.pyc
Binary file not shown.
Binary file modified app/__pycache__/test_app.cpython-311-pytest-8.3.3.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from app import app, db
import re # Regular expressions for email validation
from app.rss_to_json import fetch_rss_to_json, fetch_products_to_json, fetch_tools_to_json
from flask_cors import CORS
from flask_cors import CORS # type: ignore

# give acess to frontend
CORS(app, origins=["http://localhost:3000"])
Expand Down
11 changes: 10 additions & 1 deletion app/rss_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

# Function to fetch and convert RSS feed to JSON for news
def fetch_rss_to_json(feed_url):
# Clear the existing data in the collection
articles_collection.delete_many({}) # Delete all previous articles

feed = feedparser.parse(feed_url)
articles = []

Expand All @@ -22,7 +25,7 @@ def fetch_rss_to_json(feed_url):
article = {
'title': entry.title,
'link': entry.link,
'summary': entry.summary,
# 'summary': entry.summary,
'published': entry.published
}
articles.append(article)
Expand All @@ -37,6 +40,9 @@ def fetch_rss_to_json(feed_url):

# Function to fetch and convert RSS feed for products
def fetch_products_to_json(feed_url):
# Clear the existing data in the collection
products_collection.delete_many({}) # Delete all previous products

feed = feedparser.parse(feed_url)
products = []

Expand All @@ -63,6 +69,9 @@ def fetch_products_to_json(feed_url):

# Function to fetch and convert RSS feed for tools
def fetch_tools_to_json(feed_url):
# Clear the existing data in the collection
tools_collection.delete_many({}) # Delete all previous tools

feed = feedparser.parse(feed_url)
tools = []

Expand Down
4 changes: 2 additions & 2 deletions app/test_app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
import requests # request library to make HTTP request to the Falsk API

# if need to do the pytest, need to commit the flask-cors
BASE_URL_NEWS = "http://localhost:5001/newest"
BASE_URL_PRODUCTS = "http://localhost:5001/products"
BASE_URL_CATEGORIES = "http://localhost:5001/categories"
Expand All @@ -24,7 +24,7 @@ def test_get_news(self):
# Check if the response has the correct structure
self.assertIn('title', data[0], "Response is missing 'title' field")
self.assertIn('link', data[0], "Response is missing 'link' field")
self.assertIn('summary', data[0], "Response is missing 'summary' field")
# self.assertIn('summary', data[0], "Response is missing 'summary' field")
self.assertIn('published', data[0], "Response is missing 'published' field")

def test_get_products(self):
Expand Down

0 comments on commit db3e5d4

Please sign in to comment.