func clearCookies(client *mwclient.Client, cookieFile string) { cookies := mwlib.ReadCookies(cookieFile) for idx, _ := range cookies { cookies[idx].MaxAge = -1 } client.LoadCookies(cookies) }
func main() { args, flags := parseFlags() if flags.Operator == "" { warn.Print("Operator email / username not set.") return } if flags.MappingFile == "" { warn.Print("Category mapping file path not set.") return } if flags.ExceptionFile == "" { warn.Print("Category exception file path not set.") return } if flags.RegexFile == "" { warn.Print("Category regex file path not set.") return } if flags.CookieFile == "" { warn.Print("Cookie cache file path not set.") return } verbose := get_verbose(flags.Verbose) client, err := mwclient.New("https://commons.wikimedia.org/w/api.php", "takenwith "+flags.Operator) if err != nil { panic(err) } client.Maxlag.On = true cookies := mwlib.ReadCookies(flags.CookieFile) client.LoadCookies(cookies) categoryMap := fillCategoryMap(flags.MappingFile) // makemodel -> category // All known categories, including those that aren't catmapping // targets. allCategories := fillCategories(categoryMap, flags.ExceptionFile) catRegex := fillRegex(flags.RegexFile) var stats stats defer EndProc(client, &stats, flags.CookieFile) if !checkLogin(client) { if !login(client, flags) { return } } numArgs := len(args) if numArgs == 0 || numArgs > 2 { warn.Print("Command [timestamp] expected.") return } if strings.HasPrefix(args[0], "File:") { if numArgs > 1 { warn.Print("Unexpected parameter.") return } processOneFile(args[0], client, flags, verbose, categoryMap, allCategories, catRegex, &stats) } else if args[0] == "Random" { if numArgs > 1 { warn.Print("Unexpected parameter.") return } processRandom(client, flags, verbose, categoryMap, allCategories, catRegex, &stats) } else if strings.HasPrefix(args[0], "Page:") { if numArgs > 1 { warn.Print("Unexpected parameter.") return } processPage(args[0][5:], client, flags, verbose, categoryMap, allCategories, catRegex, &stats) } else { var ts timestamp if numArgs == 2 { ts, err = newTimestamp(args[1], true) } else { ts, err = newTimestamp("", false) } if err != nil { printBadTimestamp() os.Exit(1) } if strings.HasPrefix(args[0], "User:"******"Category:") { processCategory(args[0], ts, client, flags, verbose, categoryMap, allCategories, catRegex, &stats) } else if args[0] == "All" { if numArgs != 2 { warn.Print("Timestamp required.") return } processAll(ts, client, flags, verbose, categoryMap, allCategories, catRegex, &stats) } else { warn.Print("Unknown command.") return } } }