1 line
25 KiB
JSON
1 line
25 KiB
JSON
{"repo": "arif-u-ahmed/climanews", "files": {"server.js": {"cf2e9b616d31763aeec183d0dc594942395ff6a2": {"t": 1785745530.762517, "n": 3105, "h": "00e5f4a42fa6ada9", "c": "require('dotenv').config(); // .env Support\nconst express = require('express'); // Web framework for Node.js\nconst path = require('path'); // Node.js module for working with file paths\nconst axios = require('axios');\nconst cheerio = require('cheerio'); // Add Cheerio for HTML parsing\nconst app = express();\napp.use(express.json());\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public'))); // Look for static files within the public directory\n\n// 2. Summarize the news article with DeepSeek API\napp.post('/summarize', async (req, res) => { // Handles POST requests to /summarize endpoint by using async function\n const { url } = req.body; // Extracts URL from request body using req.body\n if (!url) return res.status(400).json({ error: 'No URL provided' }); // Returns error if no URL is provided by using res.status(400)\n\n try {\n // 1. Fetch the article HTML using Axios\n const { data: html } = await axios.get(url); // Fetches HTML from the URL using axios.get (HTTP GET request)\n // 2. Extract main content using Cheerio\n const $ = cheerio.load(html); // Loads HTML into Cheerio for parsing (jQuery-like syntax)\n // Get all paragraphs and join their text\n const articleText = $('p').map((i, el) => $(el).text()).get().join('\\n'); // Selects all <p> tags, extracts text, joins with newlines\n\n // 3. Connect to DeepSeek API\n const response = await axios.post(\n 'https://api.deepseek.com/v1/chat/completions',\n {\n model: \"deepseek-chat\",\n messages: [{ role: \"user\", content: `Summarize this news (do not include any other text, only the summary): ${articleText}` }]\n },\n {\n headers: {\n 'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,\n 'Content-Type': 'application/json'\n }\n }\n );\n const summary = response.data.choices[0].message.content; // Gets summary text from DeepSeek API response \n res.json({ summary }); // Sends summary as JSON response to client\n } catch (err) { // Handles errors if the request fails or the API call fails\n res.status(500).json({ error: err.message }); // Sends error message as JSON response\n }\n});\n\n// Add WorldNews API news endpoint\napp.post('/news', async (req, res) => {\n const { latitude, longitude } = req.body;\n if (!latitude || !longitude) return res.status(400).json({ error: 'No coordinates provided' });\n try {\n const radius = 50; // kilometers, adjust as needed\n const url = `https://api.worldnewsapi.com/search-news?location-filter=${latitude},${longitude},${radius}&language=en&number=10&api-key=${process.env.WORLDNEWS_API_KEY}`;\n const response = await axios.get(url);\n res.json({ articles: response.data.news });\n } catch (err) {\n res.status(500).json({ error: err.message });\n }\n});\n\n// Start the Server\napp.listen(PORT, () => { // Listen on the specified port\n console.log(`Server listening at http://localhost:${PORT}`); // Log a message to the console\n});"}, "5bbf72de3076c70076f615c775fa9c2fc180bc8b": {"t": 1785753898.9022403, "n": 3105, "h": "00e5f4a42fa6ada9", "c": "require('dotenv').config(); // .env Support\nconst express = require('express'); // Web framework for Node.js\nconst path = require('path'); // Node.js module for working with file paths\nconst axios = require('axios');\nconst cheerio = require('cheerio'); // Add Cheerio for HTML parsing\nconst app = express();\napp.use(express.json());\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public'))); // Look for static files within the public directory\n\n// 2. Summarize the news article with DeepSeek API\napp.post('/summarize', async (req, res) => { // Handles POST requests to /summarize endpoint by using async function\n const { url } = req.body; // Extracts URL from request body using req.body\n if (!url) return res.status(400).json({ error: 'No URL provided' }); // Returns error if no URL is provided by using res.status(400)\n\n try {\n // 1. Fetch the article HTML using Axios\n const { data: html } = await axios.get(url); // Fetches HTML from the URL using axios.get (HTTP GET request)\n // 2. Extract main content using Cheerio\n const $ = cheerio.load(html); // Loads HTML into Cheerio for parsing (jQuery-like syntax)\n // Get all paragraphs and join their text\n const articleText = $('p').map((i, el) => $(el).text()).get().join('\\n'); // Selects all <p> tags, extracts text, joins with newlines\n\n // 3. Connect to DeepSeek API\n const response = await axios.post(\n 'https://api.deepseek.com/v1/chat/completions',\n {\n model: \"deepseek-chat\",\n messages: [{ role: \"user\", content: `Summarize this news (do not include any other text, only the summary): ${articleText}` }]\n },\n {\n headers: {\n 'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,\n 'Content-Type': 'application/json'\n }\n }\n );\n const summary = response.data.choices[0].message.content; // Gets summary text from DeepSeek API response \n res.json({ summary }); // Sends summary as JSON response to client\n } catch (err) { // Handles errors if the request fails or the API call fails\n res.status(500).json({ error: err.message }); // Sends error message as JSON response\n }\n});\n\n// Add WorldNews API news endpoint\napp.post('/news', async (req, res) => {\n const { latitude, longitude } = req.body;\n if (!latitude || !longitude) return res.status(400).json({ error: 'No coordinates provided' });\n try {\n const radius = 50; // kilometers, adjust as needed\n const url = `https://api.worldnewsapi.com/search-news?location-filter=${latitude},${longitude},${radius}&language=en&number=10&api-key=${process.env.WORLDNEWS_API_KEY}`;\n const response = await axios.get(url);\n res.json({ articles: response.data.news });\n } catch (err) {\n res.status(500).json({ error: err.message });\n }\n});\n\n// Start the Server\napp.listen(PORT, () => { // Listen on the specified port\n console.log(`Server listening at http://localhost:${PORT}`); // Log a message to the console\n});"}, "42a4374d7cb7b8c9a84c3652fb2dc4d95ccd8379": {"t": 1785753900.7274656, "n": 2483, "h": "5046594934eb3606", "c": "require('dotenv').config(); // .env Support\nconst express = require('express'); // Web framework for Node.js\nconst path = require('path'); // Node.js module for working with file paths\nconst axios = require('axios');\nconst cheerio = require('cheerio'); // Add Cheerio for HTML parsing\nconst app = express();\napp.use(express.json());\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public'))); // Look for static files within the public directory\n\n// 2. Summarize the news article with DeepSeek API\napp.post('/summarize', async (req, res) => { // Handles POST requests to /summarize endpoint by using async function\n const { url } = req.body; // Extracts URL from request body using req.body\n if (!url) return res.status(400).json({ error: 'No URL provided' }); // Returns error if no URL is provided by using res.status(400)\n\n try {\n // 1. Fetch the article HTML using Axios\n const { data: html } = await axios.get(url); // Fetches HTML from the URL using axios.get (HTTP GET request)\n // 2. Extract main content using Cheerio\n const $ = cheerio.load(html); // Loads HTML into Cheerio for parsing (jQuery-like syntax)\n // Get all paragraphs and join their text\n const articleText = $('p').map((i, el) => $(el).text()).get().join('\\n'); // Selects all <p> tags, extracts text, joins with newlines\n\n // 3. Connect to DeepSeek API\n const response = await axios.post(\n 'https://api.deepseek.com/v1/chat/completions',\n {\n model: \"deepseek-chat\",\n messages: [{ role: \"user\", content: `Summarize this news (do not include any other text, only the summary): ${articleText}` }]\n },\n {\n headers: {\n 'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,\n 'Content-Type': 'application/json'\n }\n }\n );\n const summary = response.data.choices[0].message.content; // Gets summary text from DeepSeek API response \n res.json({ summary }); // Sends summary as JSON response to client\n } catch (err) { // Handles errors if the request fails or the API call fails\n res.status(500).json({ error: err.message }); // Sends error message as JSON response\n }\n});\n\n// Start the Server\napp.listen(PORT, () => { // Listen on the specified port\n console.log(`Server listening at http://localhost:${PORT}`); // Log a message to the console\n});"}, "23037f390675caddafcb0f53f836f089a50c1690": {"t": 1785753902.1316252, "n": 2439, "h": "89f38e8381059de7", "c": "require('dotenv').config(); // .env Support\nconst express = require('express'); // Web framework for Node.js\nconst path = require('path'); // Node.js module for working with file paths\nconst axios = require('axios');\nconst cheerio = require('cheerio'); // Add Cheerio for HTML parsing\nconst app = express();\napp.use(express.json());\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public'))); // Look for static files within the public directory\n\n// 2. Summarize the news article with DeepSeek API\napp.post('/summarize', async (req, res) => { // Handles POST requests to /summarize endpoint by using async function\n const { url } = req.body; // Extracts URL from request body using req.body\n if (!url) return res.status(400).json({ error: 'No URL provided' }); // Returns error if no URL is provided by using res.status(400)\n\n try {\n // 1. Fetch the article HTML using Axios\n const { data: html } = await axios.get(url); // Fetches HTML from the URL using axios.get (HTTP GET request)\n // 2. Extract main content using Cheerio\n const $ = cheerio.load(html); // Loads HTML into Cheerio for parsing (jQuery-like syntax)\n // Get all paragraphs and join their text\n const articleText = $('p').map((i, el) => $(el).text()).get().join('\\n'); // Selects all <p> tags, extracts text, joins with newlines\n\n // 3. Connect to DeepSeek API\n const response = await axios.post(\n 'https://api.deepseek.com/v1/chat/completions',\n {\n model: \"deepseek-chat\",\n messages: [{ role: \"user\", content: `Summarize this news (do not include any other text, only the summary): ${articleText}` }]\n },\n {\n headers: {\n 'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,\n 'Content-Type': 'application/json'\n }\n }\n );\n const summary = response.data.choices[0].message.content; // Gets summary text from DeepSeek API response\n res.json({ summary }); // Sends summary as JSON response to client\n } catch (err) { // Handles errors\n res.status(500).json({ error: err.message }); // Sends error message as JSON response\n }\n});\n\n// Start the Server\napp.listen(PORT, () => { // Listen on the specified port\n console.log(`Server listening at http://localhost:${PORT}`); // Log a message to the console\n});"}, "537fe7abab6ac3d23157a92fce72a8a71916dcd1": {"t": 1785753903.494185, "n": 1891, "h": "2f20a9a932828b42", "c": "require('dotenv').config(); // .env Support\nconst express = require('express'); // Web framework for Node.js\nconst path = require('path'); // Node.js module for working with file paths\nconst axios = require('axios');\nconst cheerio = require('cheerio'); // Add Cheerio for HTML parsing\nconst app = express();\napp.use(express.json());\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public'))); // Look for static files within the public directory\n\n// 2. Summarize the news article\napp.post('/summarize', async (req, res) => {\n const { url } = req.body;\n if (!url) return res.status(400).json({ error: 'No URL provided' });\n\n try {\n // 1. Fetch the article HTML\n const { data: html } = await axios.get(url);\n\n // 2. Extract main content using Cheerio\n const $ = cheerio.load(html);\n // Get all paragraphs and join their text\n const articleText = $('p').map((i, el) => $(el).text()).get().join('\\n');\n\n // 3. Summarize with DeepSeek\n const response = await axios.post(\n 'https://api.deepseek.com/v1/chat/completions',\n {\n model: \"deepseek-chat\",\n messages: [{ role: \"user\", content: `Summarize this news (do not include any other text, only the summary): ${articleText}` }]\n },\n {\n headers: {\n 'Authorization': `Bearer ${process.env.DEEPSEEK_API_KEY}`,\n 'Content-Type': 'application/json'\n }\n }\n );\n const summary = response.data.choices[0].message.content;\n res.json({ summary });\n } catch (err) {\n res.status(500).json({ error: err.message });\n }\n});\n\n// Start the Server\napp.listen(PORT, () => { // Listen on the specified port\n console.log(`Server listening at http://localhost:${PORT}`); // Log a message to the console\n});"}, "e467e48baf2fd7d6ff91b15894ed5add9cefff80": {"t": 1785753904.7088487, "n": 651, "h": "3f058c601bdbb428", "c": "require('dotenv').config(); // .env Support\nconst express = require('express'); // Web framework for Node.js\nconst path = require('path'); // Node.js module for working with file paths\n\nconst app = express();\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public'))); // Look for static files within the public directory\n\n// Start the Server\napp.listen(PORT, () => { // Listen on the specified port\n console.log(`Server listening at http://localhost:${PORT}`); // Log a message to the console\n});"}, "5b221a93b4a2cfbddc5060e881977b68a1906fd5": {"t": 1785753906.5243158, "n": 534, "h": "fa6c077f0c21a062", "c": "require('dotenv').config(); // .env Support\nconst express = require('express'); // Web framework for Node.js\nconst path = require('path'); // Node.js module for working with file paths\n\nconst app = express();\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public')));\n\n// Start the Server\napp.listen(PORT, () => {\n console.log(`Server listening at http://localhost:${PORT}`);\n});"}, "79f93284fd2b26026c0b0d1cb31d5ac01a41d28e": {"t": 1785753909.7420683, "n": 1966, "h": "0edc5424d8da2830", "c": "require('dotenv').config(); // .env Support\nconst express = require('express');\nconst axios = require('axios');\nconst cors = require('cors');\nconst path = require('path'); // Node.js module for working with file paths\n\nconst app = express();\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\napp.use(cors());\n\n// --- Middleware ---\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public')));\n\n// This is where you can serve your main HTML file\napp.get('/', (req, res) => {\n res.sendFile(path.join(__dirname, 'public', 'index.html'));\n});\n\n// --- API Routes (This is where your backend logic goes) ---\n// Example API endpoint\napp.get('/api/message', (req, res) => {\n res.json({ message: 'Hello from the Express server!' });\n});\n\napp.get('/api/news', async (req, res) => {\n try {\n const response = await axios.get(`https://newsapi.org/v2/top-headlines?country=us&apiKey=${process.env.NEWS_API_KEY}`);\n res.json(response.data);\n } catch (error) {\n console.error(error.message);\n res.status(500).json({error: 'Failed to fetch news.'});\n }\n});\n\n// Example POST endpoint (requires body parsing middleware)\napp.use(express.json()); // Middleware to parse JSON request bodies\napp.use(express.urlencoded({ extended: true })); // Middleware to parse URL-encoded bodies\n\napp.post('/api/submit-form', (req, res) => {\n console.log('Form data received:', req.body);\n // Add logic here to process the data (e.g., save to database)\n res.json({ status: 'success', receivedData: req.body });\n});\n\n// Catch-all for 404 Not Found\napp.use((req, res, next) => {\n res.status(404).sendFile(path.join(__dirname, 'public', '404.html')); // Create a 404.html page\n // Or send a simple text response: res.status(404).send(\"Sorry, can't find that!\");\n});\n\n// Start the Server\napp.listen(PORT, () => {\n console.log(`Server listening at http://localhost:${PORT}`);\n});"}, "41e667060d952a9f1bb29932b290e13a29dfe293": {"t": 1785753910.9171476, "n": 1922, "h": "4c7cd604be1fa3a5", "c": "const express = require('express');\nconst axios = require('axios');\nconst cors = require('cors');\nconst path = require('path'); // Node.js module for working with file paths\n\nconst app = express();\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\napp.use(cors());\n\n// --- Middleware ---\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public')));\n\n// This is where you can serve your main HTML file\napp.get('/', (req, res) => {\n res.sendFile(path.join(__dirname, 'public', 'index.html'));\n});\n\n// --- API Routes (This is where your backend logic goes) ---\n// Example API endpoint\napp.get('/api/message', (req, res) => {\n res.json({ message: 'Hello from the Express server!' });\n});\n\napp.get('/api/news', async (req, res) => {\n try {\n const response = await axios.get('https://newsapi.org/v2/top-headlines?country=us&apiKey=${process.env.NEWS_API_KEY}');\n res.json(response.data);\n } catch (error) {\n console.error(error.message);\n res.status(500).json({error: 'Failed to fetch news.'});\n }\n});\n\n// Example POST endpoint (requires body parsing middleware)\napp.use(express.json()); // Middleware to parse JSON request bodies\napp.use(express.urlencoded({ extended: true })); // Middleware to parse URL-encoded bodies\n\napp.post('/api/submit-form', (req, res) => {\n console.log('Form data received:', req.body);\n // Add logic here to process the data (e.g., save to database)\n res.json({ status: 'success', receivedData: req.body });\n});\n\n// Catch-all for 404 Not Found\napp.use((req, res, next) => {\n res.status(404).sendFile(path.join(__dirname, 'public', '404.html')); // Create a 404.html page\n // Or send a simple text response: res.status(404).send(\"Sorry, can't find that!\");\n});\n\n// Start the Server\napp.listen(port, () => {\n console.log(`Server listening at http://localhost:${port}`);\n});"}, "3f5fa45706a29ed53297b18db911476e83c5f47d": {"t": 1785753912.7170758, "n": 1942, "h": "1da32fb24d97fdd4", "c": "const express = require('express');\nconst axios = require('axios');\nconst cors = require('cors');\nconst path = require('path'); // Node.js module for working with file paths\n\nconst app = express();\nconst PORT = process.env.PORT || 3000; // Use environment variable or default to 3000\n\napp.use(cors());\n\n// --- Middleware ---\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public')));\n\n// This is where you can serve your main HTML file\napp.get('/', (req, res) => {\n res.sendFile(path.join(__dirname, 'public', 'index.html'));\n});\n\n// --- API Routes (This is where your backend logic goes) ---\n// Example API endpoint\napp.get('/api/message', (req, res) => {\n res.json({ message: 'Hello from the Express server!' });\n});\n\napp.get('/api/news', async (req, res) => {\n try {\n const response = await axios.get('https://newsapi.org/v2/top-headlines?country=us&apiKey=${process.env.17862bc5749540cb8dc46ffc9fa078d8}');\n res.json(response.data);\n } catch (error) {\n console.error(error.message);\n res.status(500).json({error: 'Failed to fetch news.'});\n }\n});\n\n// Example POST endpoint (requires body parsing middleware)\napp.use(express.json()); // Middleware to parse JSON request bodies\napp.use(express.urlencoded({ extended: true })); // Middleware to parse URL-encoded bodies\n\napp.post('/api/submit-form', (req, res) => {\n console.log('Form data received:', req.body);\n // Add logic here to process the data (e.g., save to database)\n res.json({ status: 'success', receivedData: req.body });\n});\n\n// Catch-all for 404 Not Found\napp.use((req, res, next) => {\n res.status(404).sendFile(path.join(__dirname, 'public', '404.html')); // Create a 404.html page\n // Or send a simple text response: res.status(404).send(\"Sorry, can't find that!\");\n});\n\n// Start the Server\napp.listen(port, () => {\n console.log(`Server listening at http://localhost:${port}`);\n});"}, "a8536350316fa614905987ed07a3531d8fb3a22b": {"t": 1785753913.9575121, "n": 1515, "h": "346b69b3b179c34f", "c": "const express = require('express');\nconst path = require('path'); // Node.js module for working with file paths\n\nconst app = express();\nconst port = process.env.PORT || 3000; // Use environment variable or default to 3000\n\n// --- Middleware ---\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public')));\n\n// This is where you can serve your main HTML file\napp.get('/', (req, res) => {\n res.sendFile(path.join(__dirname, 'public', 'index.html'));\n});\n\n// --- API Routes (This is where your backend logic goes) ---\n// Example API endpoint\napp.get('/api/message', (req, res) => {\n res.json({ message: 'Hello from the Express server!' });\n});\n\n// Example POST endpoint (requires body parsing middleware)\napp.use(express.json()); // Middleware to parse JSON request bodies\napp.use(express.urlencoded({ extended: true })); // Middleware to parse URL-encoded bodies\n\napp.post('/api/submit-form', (req, res) => {\n console.log('Form data received:', req.body);\n // Add logic here to process the data (e.g., save to database)\n res.json({ status: 'success', receivedData: req.body });\n});\n\n// Catch-all for 404 Not Found\napp.use((req, res, next) => {\n res.status(404).sendFile(path.join(__dirname, 'public', '404.html')); // Create a 404.html page\n // Or send a simple text response: res.status(404).send(\"Sorry, can't find that!\");\n});\n\n// Start the Server\napp.listen(port, () => {\n console.log(`Server listening at http://localhost:${port}`);\n});"}, "5e4ece844b26704fb5f6fe1a99de5f70bcc90be6": {"t": 1785753915.3156142, "n": 1570, "h": "e2a7d7dbf7caf827", "c": "const express = require('express');\nconst path = require('path'); // Node.js module for working with file paths\n\nconst app = express();\nconst port = process.env.PORT || 3000; // Use environment variable or default to 3000\n\n// --- Middleware ---\n\n// 1. Serve static files (HTML, CSS, JS) from the 'public' directory\napp.use(express.static(path.join(__dirname, 'public')));\n\n// This is where you can serve your main HTML file\napp.get('/', (req, res) => {\n res.sendFile(path.join(__dirname, 'public', 'index.html'));\n});\n\n// --- API Routes (This is where your backend logic goes) ---\n// Example API endpoint\napp.get('/api/message', (req, res) => {\n res.json({ message: 'Hello from the Express server!' });\n});\n\n// Example POST endpoint (requires body parsing middleware)\napp.use(express.json()); // Middleware to parse JSON request bodies\napp.use(express.urlencoded({ extended: true })); // Middleware to parse URL-encoded bodies\n\napp.post('/api/submit-form', (req, res) => {\n console.log('Form data received:', req.body);\n // Add logic here to process the data (e.g., save to database)\n res.json({ status: 'success', receivedData: req.body });\n});\n\n// --- Catch-all for 404 Not Found (Optional but good practice) ---\napp.use((req, res, next) => {\n res.status(404).sendFile(path.join(__dirname, 'public', '404.html')); // Optional: Create a 404.html page\n // Or send a simple text response: res.status(404).send(\"Sorry, can't find that!\");\n});\n\n// --- Start the Server ---\napp.listen(port, () => {\n console.log(`Server listening at http://localhost:${port}`);\n});"}}}} |