-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
42 lines (35 loc) · 1.47 KB
/
app.js
File metadata and controls
42 lines (35 loc) · 1.47 KB
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
const request = require("request-promise")
const fs = require("fs")
const cheerio = require("cheerio")
const { itemIDList } = require("./items")
var itemsOnPage = []
async function downloadHTML(){
let pageHTML = await request.get("https://www.corrosionhour.com/rust-item-list/")
const $ = cheerio.load(pageHTML)
var allItems = {}
//Skip the first one as that's just the header bar
let itemsArray = $(".ch-tbl-row")
for (let index = 1; index < itemsArray.length; index++) {
let item = $(".ch-item-list-table > tbody > tr:nth-child("+ index + ")")
let shortName = item.find("td")[1].children[0].data
let itemIdNumber = item.find("td")[2].children[0].data
shortName = shortName.toString()
itemIdNumber = parseFloat(itemIdNumber)
// const itemIdentity = {
// [shortName] : itemIdNumber
// }
allItems[shortName] = itemIdNumber
let caseLine = "case " + itemIdNumber + ": return " + "\"" + shortName + "\"" + ";" + "\n"
fs.appendFile('itemIDS.txt', caseLine, function (err) {
if (err) {
// append failed
} else {
// done
}
})
}
var jsonData = JSON.stringify(allItems, null, "\t");
fs.writeFileSync("itemsJsonDec2020.json", jsonData)
//For now I just manually take the entire json string and copy it into the items.js file so const itemIDList = { HERE GOES ALL THE JSON DATA }
}
downloadHTML()