-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (55 loc) · 1.78 KB
/
index.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
62
var axios = require('axios');
var cheerio = require('cheerio');
var fs = require('fs');
var util = require('util');
var g2a = require('./g2a.js');
const humbleKeysUrl = "https://www.humblebundle.com/home/keys";
const humbleOrderUrl = "https://www.humblebundle.com/api/v1/order/%s?all_tpkds=true";
//TODO: automatic Cookie retrieve
var cookieString = fs.readFileSync('./cookies', 'utf8').toString();
const headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Cookie': cookieString,
'Accept': '/',
'Connection': 'keep-alive'
}
const options = {
url: humbleKeysUrl,
method: 'GET',
headers: headers
};
var options2 = {
url: '',
method: 'GET',
headers: headers
};
function getOrderDetails(orderID){
options2.url = util.format(humbleOrderUrl, orderID);
axios(options2).then((response) => {
response.data["tpkd_dict"]["all_tpks"].forEach((elem) => {
g2a.priceCheck(elem["human_name"]).then((response2) => {
var price = 0;
if(response2.data["products"].length > 0){
price = response2.data["products"][0]["minPrice"];
}
console.log(elem["human_name"], elem["steam_app_id"], "redeemed_key_val" in elem, price);
});
});
});
}
function getKeyList(){
axios(options).then((response) => {
var $ = cheerio.load(response.data);
var scripts = $('script').filter(function() {
return ($(this).html().indexOf('var gamekeys') > -1);
});
const matchkeys = scripts.first().html().match(/var gamekeys = (.*);/);
var keys = JSON.parse(matchkeys[1]);
keys.forEach((elem) => {
console.log(elem);
getOrderDetails(elem);
})
});
}
//getOrderDetails('axzRXRbdzFhq8YZM');
getKeyList();