Spaces:
Running
Running
Update news.js
Browse files
news.js
CHANGED
@@ -89,28 +89,35 @@ function convertToISO8601(dateString) {
|
|
89 |
return new Date(dateString).toISOString();
|
90 |
}
|
91 |
|
|
|
92 |
const uploadNewsOnDatabase = async (data, category, newsSource, newsSourceName) => {
|
93 |
try {
|
94 |
|
95 |
|
96 |
data.forEach(async (item) => {
|
|
|
97 |
|
98 |
-
|
99 |
-
INSERT INTO news (title, source, article_url, image_url, published_date, category, source_name)
|
100 |
-
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
101 |
`;
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
});
|
116 |
|
@@ -120,4 +127,5 @@ const uploadNewsOnDatabase = async (data, category, newsSource, newsSourceName)
|
|
120 |
}
|
121 |
}
|
122 |
|
|
|
123 |
module.exports = { getNews };
|
|
|
89 |
return new Date(dateString).toISOString();
|
90 |
}
|
91 |
|
92 |
+
|
93 |
const uploadNewsOnDatabase = async (data, category, newsSource, newsSourceName) => {
|
94 |
try {
|
95 |
|
96 |
|
97 |
data.forEach(async (item) => {
|
98 |
+
try {
|
99 |
|
100 |
+
const query = `
|
101 |
+
INSERT INTO news (id, title, source, article_url, image_url, published_date, category, source_name)
|
102 |
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
103 |
`;
|
104 |
+
const values = [
|
105 |
+
item.title.replace(/[^a-zA-Z0-9]/g, '') ,
|
106 |
+
item.title,
|
107 |
+
newsSource,
|
108 |
+
item.link,
|
109 |
+
item.enclosure ? item.enclosure.url : null,
|
110 |
+
convertToISO8601(item.pubDate),
|
111 |
+
category,
|
112 |
+
newsSourceName
|
113 |
+
];
|
114 |
+
|
115 |
+
await pool.query(query, values);
|
116 |
+
|
117 |
+
} catch (e) {
|
118 |
+
// console.log(e);
|
119 |
+
}
|
120 |
+
|
121 |
|
122 |
});
|
123 |
|
|
|
127 |
}
|
128 |
}
|
129 |
|
130 |
+
|
131 |
module.exports = { getNews };
|