fix: Reworked logic to better deal with being logged out in CultivateLabs platforms

This commit is contained in:
NunoSempere 2021-07-09 18:15:49 +02:00
parent 87db98ec45
commit d9390faeec
2 changed files with 27 additions and 9 deletions

View File

@ -131,11 +131,17 @@ async function fetchStats(questionUrl, cookie){
return result
}
function isEnd(html){
if(html.includes("You need to sign in or sign up before continuing")){
throw Error("You need to sign in or sign up before continuing")
}
function isNotSignedIn(html){
let isNotSignedInBool = html.includes("You need to sign in or sign up before continuing") || html.includes("Sign up")
if(isNotSignedInBool){
console.log("Error: Not signed in.")
}
console.log(`isNotSignedIn? ${isNotSignedInBool}`)
return isNotSignedInBool
}
function isEnd(html){
let isEndBool = html.includes("No questions match your filter")
if(isEndBool){
//console.log(html)
@ -156,7 +162,7 @@ async function csetforetell_inner(cookie){
let results = []
let init = Date.now()
// console.log("Downloading... This might take a couple of minutes. Results will be shown.")
while(!isEnd(response)){
while(!isEnd(response) && !isNotSignedIn(response)){
let htmlLines = response.split("\n")
let h4elements = htmlLines.filter(str => str.includes("<h5><a href=") || str.includes("<h4><a href="))

View File

@ -107,11 +107,23 @@ async function fetchStats(questionUrl, cookie) {
return result
}
function isEnd(html) {
if(html.includes("You need to sign in or sign up before continuing")){
throw Error("You need to sign in or sign up before continuing")
function isNotSignedIn(html){
let isNotSignedInBool = html.includes("You need to sign in or sign up before continuing") || html.includes("Sign up")
if(isNotSignedIn){
console.log("Error: Not signed in.")
}
return html.includes("No questions match your filter")
console.log(`isNotSignedIn? ${isNotSignedInBool}`)
return isNotSignedInBool
}
function isEnd(html){
let isEndBool = html.includes("No questions match your filter")
if(isEndBool){
//console.log(html)
}
console.log(`IsEnd? ${isEndBool}`)
return isEndBool
}
function sleep(ms) {
@ -126,7 +138,7 @@ async function goodjudgmentopen_inner(cookie) {
let results = []
let init = Date.now()
// console.log("Downloading... This might take a couple of minutes. Results will be shown.")
while (!isEnd(response)) {
while(!isEnd(response) && !isNotSignedIn(response)){
// console.log(`Page #${i}`)
let htmlLines = response.split("\n")
let h5elements = htmlLines.filter(str => str.includes("<h5><a href="))