Skip to content

Commit

Permalink
Fixed commented out same page check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fulmir committed Jun 1, 2023
1 parent 9ccf169 commit 2034323
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions importer/mediawiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,54 +110,54 @@ func Import(wikidata string, dryrun bool, username, password, url string) error
continue
}

// if strings.TrimSpace(fileContent) == strings.TrimSpace(content) {
// logrus.Debugf("UNCHANGED %s", pageName)
// unchanged[pageTitle] = struct{}{}
// } else {
if content != "" {
logrus.Infof("UPDATING %s", pageName)
updates[pageTitle] = struct{}{}
}
if !dryrun {
errCheck := true
for i := 0; i < 5 && errCheck; i++ {
if err := w.Edit(map[string]string{
"title": pageName,
"text": fileContent,
"summary": "automated page update",
}); err != nil {
logrus.Debugf("Error writing page %s to wiki: %s\n", pageName, err)

errCode := strings.Split(err.Error(), ":")[0]

if errCode == "badtoken" {
logrus.Warnf("CSRF Token auth failed while writing page %s to wiki, retrying after attempt %s: %s\n", pageName, strconv.Itoa(i+1), err)
errCheck = true
delete(w.Tokens, "csrf")
w.Logout()
w.Login(username, password)
} else if strings.Contains(errCode, "invalid") || strings.Contains(errCode, "denied") {
errCheck = false
logrus.Errorf("Error writing page %s to wiki, retrying after attempt %s: %s\n", pageName, strconv.Itoa(i+1), err)
} else if strings.Contains(errCode, "edit successful") {
errCheck = false
logrus.Warnf("Edit successful but contained no changes to page %s to wiki: %s\n", pageName, err)
} else if strings.Contains(errCode, "error occured during HTTP request") {
errCheck = true
logrus.Errorf("Error writing page %s to wiki, retrying after attempt %s: %s\n", pageName, strconv.Itoa(i+1), err)
w.Maxlag.Timeout = "90"
if strings.TrimSpace(fileContent) == strings.TrimSpace(content) {
logrus.Debugf("UNCHANGED %s", pageName)
unchanged[pageTitle] = struct{}{}
} else {
if content != "" {
logrus.Infof("UPDATING %s", pageName)
updates[pageTitle] = struct{}{}
}
if !dryrun {
errCheck := true
for i := 0; i < 5 && errCheck; i++ {
if err := w.Edit(map[string]string{
"title": pageName,
"text": fileContent,
"summary": "automated page update",
}); err != nil {
logrus.Debugf("Error writing page %s to wiki: %s\n", pageName, err)

errCode := strings.Split(err.Error(), ":")[0]

if errCode == "badtoken" {
logrus.Warnf("CSRF Token auth failed while writing page %s to wiki, retrying after attempt %s: %s\n", pageName, strconv.Itoa(i+1), err)
errCheck = true
delete(w.Tokens, "csrf")
w.Logout()
w.Login(username, password)
} else if strings.Contains(errCode, "invalid") || strings.Contains(errCode, "denied") {
errCheck = false
logrus.Errorf("Error writing page %s to wiki, retrying after attempt %s: %s\n", pageName, strconv.Itoa(i+1), err)
} else if strings.Contains(errCode, "edit successful") {
errCheck = false
logrus.Warnf("Edit successful but contained no changes to page %s to wiki: %s\n", pageName, err)
} else if strings.Contains(errCode, "error occured during HTTP request") {
errCheck = true
logrus.Errorf("Error writing page %s to wiki, retrying after attempt %s: %s\n", pageName, strconv.Itoa(i+1), err)
w.Maxlag.Timeout = "90"
} else {
errCheck = true
logrus.Errorf("Error writing page %s to wiki, retrying after attempt %s: %s\n", pageName, strconv.Itoa(i+1), err)
}
} else {
errCheck = true
logrus.Errorf("Error writing page %s to wiki, retrying after attempt %s: %s\n", pageName, strconv.Itoa(i+1), err)
w.Maxlag.Timeout = "30"
errCheck = false
logrus.Infof("SUCCESSFULLY UPDATED %s", pageName)
}
} else {
w.Maxlag.Timeout = "30"
errCheck = false
logrus.Infof("SUCCESSFULLY UPDATED %s", pageName)
}
}
}
//}
}
}

Expand Down

0 comments on commit 2034323

Please sign in to comment.