-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
62 lines (35 loc) · 1.62 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const { getUrlsInTimeInterval_HT, addCategories_HT, getUrlsInCategories_HT, scrapeUrls_HT} = require("./page-scrape");
const { getUrlsFromSitemap_HT } = require("./sitemap-update");
const { generateNotes } = require("./notes-and-qa")
const { createTableNews, updateFromSelectNews_HT, insertIntoNews_HT } = require("./news-sql");
const { initPG, newsPool } = require("./db-config");
// to be called only once when starting new DB
const initDB = async() => {
await createTableNews();
}
const main = async () => {
SitemapUrl_HT = "https://www.hindustantimes.com/sitemap/may-2023.xml";
urlObjects = await getUrlsFromSitemap_HT(SitemapUrl_HT);
addCategories_HT(urlObjects);
h_to_ms = 60 * 60 * 1000;
// afterTime = 1685431760000;
// beforeTime = 1685431780000;
afterTime = Date.now() - 1 * h_to_ms;
beforeTime = Date.now();
urlObjectsLatest = getUrlsInTimeInterval_HT(urlObjects, afterTime, beforeTime);
categories = ["cricket", "world-news"];
urlObjectsDesired = getUrlsInCategories_HT(urlObjectsLatest, categories);
console.log(urlObjectsDesired);
await updateFromSelectNews_HT(urlObjectsDesired);
console.log(urlObjectsDesired);
await scrapeUrls_HT(urlObjectsDesired);
console.log(urlObjectsDesired);
console.log(urlObjectsDesired.length);
await generateNotes(urlObjectsDesired);
console.log(urlObjectsDesired);
await insertIntoNews_HT(urlObjectsDesired);
console.log("main closed");
}
// slowest step: OpenAI API latency
// also SELECT and INSERT INTO queries run one at a time, which is slow for 100+ queries
module.exports = { initDB, main };