fix: Do not update database if signed out

This commit is contained in:
NunoSempere 2021-07-27 23:50:31 +02:00
commit ec29825d56
4 changed files with 49 additions and 9 deletions

View File

@ -45,6 +45,10 @@ async function fetchStats(questionUrl, cookie){
.then(res => res.data) .then(res => res.data)
//console.log(response) //console.log(response)
if(response.includes("Sign up or sign in to forecast")){
throw Error("Not logged in")
}
// Is binary? // Is binary?
let isbinary = response.includes("binary?":true") let isbinary = response.includes("binary?":true")
// console.log(`is binary? ${isbinary}`) // console.log(`is binary? ${isbinary}`)
@ -104,6 +108,8 @@ async function fetchStats(questionUrl, cookie){
let description = descriptionprocessed8 let description = descriptionprocessed8
// Number of forecasts // Number of forecasts
//console.log(response)
//console.log(response.split("prediction_sets_count":")[1])
let numforecasts = response.split("prediction_sets_count":")[1].split(",")[0] let numforecasts = response.split("prediction_sets_count":")[1].split(",")[0]
// console.log(numforecasts) // console.log(numforecasts)
@ -125,6 +131,16 @@ async function fetchStats(questionUrl, cookie){
return result return result
} }
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){ function isEnd(html){
let isEndBool = html.includes("No questions match your filter") let isEndBool = html.includes("No questions match your filter")
if(isEndBool){ if(isEndBool){
@ -146,7 +162,7 @@ async function csetforetell_inner(cookie){
let results = [] let results = []
let init = Date.now() let init = Date.now()
// console.log("Downloading... This might take a couple of minutes. Results will be shown.") // 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 htmlLines = response.split("\n")
let h4elements = htmlLines.filter(str => str.includes("<h5><a href=") || str.includes("<h4><a href=")) let h4elements = htmlLines.filter(str => str.includes("<h5><a href=") || str.includes("<h4><a href="))
@ -208,7 +224,11 @@ async function csetforetell_inner(cookie){
// let string = JSON.stringify(results,null, 2) // let string = JSON.stringify(results,null, 2)
// fs.writeFileSync('./data/csetforetell-questions.json', string); // fs.writeFileSync('./data/csetforetell-questions.json', string);
// console.log(results) // console.log(results)
if(results.length > 0){
await upsert(results, "csetforetell-questions") await upsert(results, "csetforetell-questions")
}else{
console.log("Not updating results, as process was not signed in")
}
let end = Date.now() let end = Date.now()
let difference = end-init let difference = end-init

View File

@ -6,7 +6,7 @@ import { upsert } from "../utils/mongo-wrapper.js"
/* Definitions */ /* Definitions */
let graphQLendpoint = "https://api.foretold.io/graphql" let graphQLendpoint = "https://api.foretold.io/graphql"
let highQualityCommunities = ["0104d8e8-07e4-464b-8b32-74ef22b49f21", "c47c6bc8-2c9b-4a83-9583-d1ed80a40fa2", "cf663021-f87f-4632-ad82-962d889a2d39", "47ff5c49-9c20-4f3d-bd57-1897c35cd42d"] let highQualityCommunities = ["0104d8e8-07e4-464b-8b32-74ef22b49f21", "c47c6bc8-2c9b-4a83-9583-d1ed80a40fa2", "cf663021-f87f-4632-ad82-962d889a2d39", "47ff5c49-9c20-4f3d-bd57-1897c35cd42d", "b2412a1d-0aa4-4e37-a12a-0aca9e440a96"]
/* Support functions */ /* Support functions */
async function fetchAllCommunityQuestions(communityId) { async function fetchAllCommunityQuestions(communityId) {

View File

@ -107,8 +107,23 @@ async function fetchStats(questionUrl, cookie) {
return result return result
} }
function isEnd(html) { function isNotSignedIn(html){
return html.includes("No questions match your filter")
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.")
}
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) { function sleep(ms) {
@ -123,7 +138,7 @@ async function goodjudgmentopen_inner(cookie) {
let results = [] let results = []
let init = Date.now() let init = Date.now()
// console.log("Downloading... This might take a couple of minutes. Results will be shown.") // 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}`) // console.log(`Page #${i}`)
let htmlLines = response.split("\n") let htmlLines = response.split("\n")
let h5elements = htmlLines.filter(str => str.includes("<h5><a href=")) let h5elements = htmlLines.filter(str => str.includes("<h5><a href="))
@ -173,7 +188,12 @@ async function goodjudgmentopen_inner(cookie) {
} }
// let string = JSON.stringify(results, null, 2) // let string = JSON.stringify(results, null, 2)
// fs.writeFileSync('./data/goodjudmentopen-questions.json', string); // fs.writeFileSync('./data/goodjudmentopen-questions.json', string);
if(results.length > 0){
await upsert(results, "goodjudmentopen-questions") await upsert(results, "goodjudmentopen-questions")
}else{
console.log("Not updating results, as process was not signed in")
}
let end = Date.now() let end = Date.now()
let difference = end - init let difference = end - init

View File

@ -182,5 +182,5 @@ export async function mongoGetAllElements(databaseName = "metaforecastDatabase",
} }
} }
// mongoGetAllElements() //mongoGetAllElements()
//mongoGetAllElements("metaforecastDatabase", "metaforecastHistory") //mongoGetAllElements("metaforecastDatabase", "metaforecastHistory")