|
@@ -37,12 +37,14 @@ import errno |
|
|
from getpass import getpass |
|
|
from getpass import getpass |
|
|
from os import chmod, path |
|
|
from os import chmod, path |
|
|
import stat |
|
|
import stat |
|
|
|
|
|
from sys import argv |
|
|
import time |
|
|
import time |
|
|
|
|
|
from urllib import urlencode |
|
|
|
|
|
|
|
|
import earwigbot |
|
|
import earwigbot |
|
|
import git |
|
|
import git |
|
|
|
|
|
|
|
|
SCRIPT_SITE = "https://en.wikipedia.org" |
|
|
|
|
|
|
|
|
SCRIPT_SITE = "en.wikipedia.org" |
|
|
SCRIPT_USER = "The Earwig" |
|
|
SCRIPT_USER = "The Earwig" |
|
|
SCRIPT_FILE = "tfdclerk.js" |
|
|
SCRIPT_FILE = "tfdclerk.js" |
|
|
COOKIE_FILE = ".cookies" |
|
|
COOKIE_FILE = ".cookies" |
|
@@ -53,6 +55,9 @@ SCRIPT_PAGE = "User:{user}/{file}".format(user=SCRIPT_USER, file=SCRIPT_FILE) |
|
|
SCRIPT_ROOT = path.dirname(path.abspath(__file__)) |
|
|
SCRIPT_ROOT = path.dirname(path.abspath(__file__)) |
|
|
REPO = git.Repo(SCRIPT_ROOT) |
|
|
REPO = git.Repo(SCRIPT_ROOT) |
|
|
|
|
|
|
|
|
|
|
|
if len(argv) > 1 and argv[1].lstrip("-").startswith("t"): |
|
|
|
|
|
SCRIPT_SITE = "test.wikipedia.org" |
|
|
|
|
|
|
|
|
def _is_clean(): |
|
|
def _is_clean(): |
|
|
""" |
|
|
""" |
|
|
Return whether there are uncommitted changes in the working directory. |
|
|
Return whether there are uncommitted changes in the working directory. |
|
@@ -113,8 +118,9 @@ def _get_site(): |
|
|
This is hacky, but it allows us to upload the script without storing the |
|
|
This is hacky, but it allows us to upload the script without storing the |
|
|
user's password in a config file like EarwigBot normally does. |
|
|
user's password in a config file like EarwigBot normally does. |
|
|
""" |
|
|
""" |
|
|
site = earwigbot.wiki.Site(base_url=SCRIPT_SITE, script_path="/w", |
|
|
|
|
|
cookiejar=_get_cookiejar(), assert_edit="user") |
|
|
|
|
|
|
|
|
site = earwigbot.wiki.Site( |
|
|
|
|
|
base_url="https://" + SCRIPT_SITE, script_path="/w", |
|
|
|
|
|
cookiejar=_get_cookiejar(), assert_edit="user") |
|
|
|
|
|
|
|
|
logged_in_as = site._get_username_from_cookies() |
|
|
logged_in_as = site._get_username_from_cookies() |
|
|
if not logged_in_as or logged_in_as != SCRIPT_USER: |
|
|
if not logged_in_as or logged_in_as != SCRIPT_USER: |
|
@@ -131,14 +137,22 @@ def main(): |
|
|
print("Uncommitted changes in working directory. Stopping.") |
|
|
print("Uncommitted changes in working directory. Stopping.") |
|
|
exit(1) |
|
|
exit(1) |
|
|
|
|
|
|
|
|
print("Uploading script to [[{page}]]...".format(page=SCRIPT_PAGE)) |
|
|
|
|
|
|
|
|
print("Uploading script to [[{page}]] on {site}...".format( |
|
|
|
|
|
page=SCRIPT_PAGE, site=SCRIPT_SITE)) |
|
|
script = _get_script() |
|
|
script = _get_script() |
|
|
site = _get_site() |
|
|
site = _get_site() |
|
|
page = site.get_page(SCRIPT_PAGE) |
|
|
page = site.get_page(SCRIPT_PAGE) |
|
|
summary = EDIT_SUMMARY.format(version=_get_version()) |
|
|
summary = EDIT_SUMMARY.format(version=_get_version()) |
|
|
|
|
|
|
|
|
page.edit(script, summary, minor=False, bot=False) |
|
|
page.edit(script, summary, minor=False, bot=False) |
|
|
|
|
|
|
|
|
|
|
|
params = { |
|
|
|
|
|
"title": page.title.replace(" ", "_"), |
|
|
|
|
|
"oldid": "prev", |
|
|
|
|
|
"diff": "cur" |
|
|
|
|
|
} |
|
|
print("Done!") |
|
|
print("Done!") |
|
|
|
|
|
print(site.url + "/w/index.php?" + urlencode(params)) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
main() |