User:Smallbot/source/GFPLM/Smallbot 6

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Commons:Bots/Requests/Smallbot 6 source

Task 1,2,4

[edit]
using System;
using System.Text;
using DotNetWikiBot;

namespace Gerald_Ford_Fix1
{
    class Program
    {
        static void Main(string[] args)
        {
            Site w = new Site("https://commons.wikimedia.org/wiki/Main_Page", "user", "pass");
            w.LogInViaApi();

            string[] catstofix = {"US National Archives Collection GRF-0056: White House Central Files Subject Files (Ford Administration), 08/09/1974 - 01/20/1977‎",
                            "US National Archives series: White House Central Files Subject Files on Countries, compiled 08/1974 - 01/1977",
                            "US National Archives series: White House Central Files Subject Files on National Security and Defense, compiled 08/1974 - 01/1977",
                            "US National Archives Collection GRF-0067: John O. Marsh Files (Ford Administration), 1974 - 1977",
                            "US National Archives series: John Marsh's War Powers Notifications Files, compiled 1975 - 1976",
                            "US National Archives Collection GRF-0127: Saigon Embassy Files Kept by Ambassador Graham Martin, 1963 - 1975",
                            "US National Archives series: Copies of Files Removed by Ambassador Graham Martin, compiled 1963 - 1975",
                            "US National Archives Collection GRF-0164: Theodore C. Marrs Files (Ford Administration), 1974 - 1977",
                            "US National Archives Collection GRF-0312: National Security Council Meetings Files (Ford Administration), 08/1974 - 11/1976‎",
                            "US National Archives Collection GRF-0314: Memoranda of Conversations (Nixon and Ford Administrations), 1973 - 1977",
                            "US National Archives Collection GRF-0324: Presidential Country Files for East Asia and the Pacific (Ford Administration), 1974 - 1977",
                            "US National Archives Collection GRF-0337: National Security Council East Asian and Pacific Affairs Staff Files (Ford Administration), 1974 - 1977",
                            "US National Archives Collection GRF-0352: Presidential Subject Files (Ford Administration), 1974 - 1977‎",
                            "US National Archives Collection GRF-WHPO: White House Photographic Office Collection (Ford Administration), 12/06/1973 - 01/20/1977",
                            "US National Archives series: Gerald and Betty Ford Historical Photographs, compiled 08/09/1974 - 01/20/1977, documenting the period 1884 - 1974‎",
                            "US National Archives series: Gerald R. Ford White House Photographs, compiled 08/09/1974 - 01/20/1977‎",
                            "US National Archives Collection GRF-0008: James E. Connor Files, 1974 - 1977‎",
                            "US National Archives Collection GRF-0047: President's Handwriting Files (Ford Administration), 1974 - 1986",
                            "US National Archives Collection GRF-0055: White House Records Office: Legislation Case Files, 08/09/1974 - 01/20/1977‎"};
            
            //load each cat, and check its files
            foreach (string cattofix in catstofix)
            {
                PageList pages = new PageList(w);
                pages.FillAllFromCategoryTree(cattofix);
                pages.FilterNamespaces(new int[] { 6 });//only files

                foreach (Page p in pages)
                {
                    p.Load();

                    //put in |Institution={{Institution:Gerald R. Ford Presidential Library}}
                    p.text = p.text.Replace("|Location=", "|Institution={{Institution:Gerald R. Ford Presidential Library}}" + Environment.NewLine + "|Location=");

                    //replace {{NARA-cooperation}}
                    p.text = p.text.Replace("{{NARA-cooperation}}", "{{Gerald R. Ford Presidential Library and Museum-cooperation}}");

                    //check if categorized
                    if (p.text.IndexOf("ategory") == -1)
                        p.text += "{{Uncategorized-GFPLM|year=2012|month=November|day=21}}";

                    p.Save("[[Commons:Bots/Requests/Smallbot 6]]: Updating location, cooperation template, and categorization status", true);
                    Bot.Wait(1);
                }
            }
            Console.WriteLine("Done.");
            Console.ReadKey();
        }
    }
}

Task 2 fix

[edit]
using System;
using System.Text;
using DotNetWikiBot;
using System.Diagnostics;

namespace Gerald_Ford_Fix1
{
    class Program
    {
        static void Main(string[] args)
        {
            Site w = new Site("https://commons.wikimedia.org/wiki/Main_Page", "user", "pass");
            w.LogInViaApi();

            string[] catstofix = {"US National Archives Collection GRF-0056: White House Central Files Subject Files (Ford Administration), 08/09/1974 - 01/20/1977‎",
                            "US National Archives series: White House Central Files Subject Files on Countries, compiled 08/1974 - 01/1977",
                            "US National Archives series: White House Central Files Subject Files on National Security and Defense, compiled 08/1974 - 01/1977",
                            "US National Archives Collection GRF-0067: John O. Marsh Files (Ford Administration), 1974 - 1977",
                            "US National Archives series: John Marsh's War Powers Notifications Files, compiled 1975 - 1976",
                            "US National Archives Collection GRF-0127: Saigon Embassy Files Kept by Ambassador Graham Martin, 1963 - 1975",
                            "US National Archives series: Copies of Files Removed by Ambassador Graham Martin, compiled 1963 - 1975",
                            "US National Archives Collection GRF-0164: Theodore C. Marrs Files (Ford Administration), 1974 - 1977",
                            "US National Archives Collection GRF-0312: National Security Council Meetings Files (Ford Administration), 08/1974 - 11/1976‎",
                            "US National Archives Collection GRF-0314: Memoranda of Conversations (Nixon and Ford Administrations), 1973 - 1977",
                            "US National Archives Collection GRF-0324: Presidential Country Files for East Asia and the Pacific (Ford Administration), 1974 - 1977",
                            "US National Archives Collection GRF-0337: National Security Council East Asian and Pacific Affairs Staff Files (Ford Administration), 1974 - 1977",
                            "US National Archives Collection GRF-0352: Presidential Subject Files (Ford Administration), 1974 - 1977‎",
                            "US National Archives Collection GRF-WHPO: White House Photographic Office Collection (Ford Administration), 12/06/1973 - 01/20/1977",
                            "US National Archives series: Gerald and Betty Ford Historical Photographs, compiled 08/09/1974 - 01/20/1977, documenting the period 1884 - 1974‎",
                            "US National Archives series: Gerald R. Ford White House Photographs, compiled 08/09/1974 - 01/20/1977‎",
                            "US National Archives Collection GRF-0008: James E. Connor Files, 1974 - 1977‎",
                            "US National Archives Collection GRF-0047: President's Handwriting Files (Ford Administration), 1974 - 1986",
                            "US National Archives Collection GRF-0055: White House Records Office: Legislation Case Files, 08/09/1974 - 01/20/1977‎"};
            
            //load each cat, and check its files
            foreach (string cattofix in catstofix)
            {
                PageList pages = new PageList(w);
                pages.FillAllFromCategoryTree(cattofix);
                pages.FilterNamespaces(new int[] { 6 });//only files

                foreach (Page p in pages)
                {
                    p.Load();

                    //check if happens twice and remove added instance
                    int first = p.text.IndexOf("{{Institution:Gerald R. Ford Presidential Library}}");
                    if (first != p.text.LastIndexOf("{{Institution:Gerald R. Ford Presidential Library}}"))
                    {
                        p.text = p.text.Replace("|Institution={{Institution:Gerald R. Ford Presidential Library}}\n", "");

                        //Add it back if not there
                        if (p.text.IndexOf("{{Institution:Gerald R. Ford Presidential Library}}") == -1)
                            p.text = p.text.Replace("|Location=", "|Institution={{Institution:Gerald R. Ford Presidential Library}}" + Environment.NewLine + "|Location=");

                        p.Save("[[Commons:Bots/Requests/Smallbot 6]]: Removing duplicate Insitution tag.", true);
                    }
                }

            }
            Console.WriteLine("Done.");
            Console.ReadKey();
        }
    }
}