Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed commented out same page check. #8

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions importer/mediawiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,46 @@ func Import(wikidata string, dryrun bool, username, password, url string) error
unchanged[pageTitle] = struct{}{}
} else {
if content != "" {
logrus.Infof("UPDATE %s", pageName)
logrus.Infof("UPDATING %s", pageName)
updates[pageTitle] = struct{}{}
}
if !dryrun {
if err := w.Edit(map[string]string{
"title": pageName,
"text": fileContent,
"summary": "automated page update",
}); err != nil {
logrus.Errorf("Error writing page %s to wiki: %s\n", pageName, err)
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 {
w.Maxlag.Timeout = "30"
errCheck = false
logrus.Infof("SUCCESSFULLY UPDATED %s", pageName)
}
}
}
}
Expand Down