Skip to content

Commit

Permalink
add debug messages and try..catch on block that fails sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
axi92 committed Nov 1, 2020
1 parent 68ce056 commit 75ff4f4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const momentTZ = require('moment-timezone');
const events = require('events');
const async = require("async");
const schedule = require('node-schedule');
const debug = require('debug')('steam-workshop-scraper');

class SteamWorkshopScraper {
constructor() {
Expand Down Expand Up @@ -111,11 +112,14 @@ class SteamWorkshopScraper {
// console.log(`Status Code: ${response.statusCode}`)
if (response.statusCode == 200) {
return data;
} else {
console.error('Scrape failed with status code:', response.statusCode);
}
});
}

ParseSteamTime(string) {
debug('ParseStreamTime:', string);
if (string.match('[0-9]{4}')) {
let parsed = moment(string, 'DD MMM, YYYY @ h:mma').format('YYYY-MM-DD HH:mm');
let a = momentTZ.tz(parsed, 'America/Los_Angeles');
Expand All @@ -126,11 +130,17 @@ class SteamWorkshopScraper {
}
} else {
let parsed = moment(string, 'DD MMM @ h:mma').format('YYYY-MM-DD HH:mm');
let a = momentTZ.tz(parsed, 'America/Los_Angeles');
if (a.isValid()) {
var time = moment(a).local();
} else {
console.error('not valid date2');
var a = momentTZ.tz(parsed, 'America/Los_Angeles');
try {
if (a.isValid()) {
var time = moment(a).local();
} else {
console.error('not valid date2');
}
} catch (error){
debug('var a is:');
debug(a);
console.error('try catch error:', error);
}
}
return time.toISOString(true);
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
},
"dependencies": {
"async": "^3.2.0",
"moment": "^2.29.0",
"debug": "^4.2.0",
"moment": "^2.29.1",
"moment-timezone": "^0.5.31",
"node-schedule": "^1.3.2",
"scrape-it": "^5.2.4"
Expand Down

0 comments on commit 75ff4f4

Please sign in to comment.