Skip to content

Instantly share code, notes, and snippets.

@legoktm
Created February 23, 2013 06:34
Show Gist options
  • Save legoktm/5018722 to your computer and use it in GitHub Desktop.
Save legoktm/5018722 to your computer and use it in GitHub Desktop.
A quick script that automatically creates your /common.js files with your global.js from meta.
#!/usr/bin/env python
"""
Copyright (C) 2013 Legoktm
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
"""
username=''
password=''
import wikitools
import oursql
import os
import time
query = """
/* SLOW_OK */
SELECT
domain,
script_path
FROM toolserver.wiki
WHERE is_closed=0"""
text = u"mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:{0}/global.js&action=raw&ctype=text/javascript');".format(username)
db_ts = oursql.connect(
host="sql-toolserver",
read_default_file=os.path.expanduser("~/.my.cnf"),
charset=None,
use_unicode=False
)
cursor = db_ts.cursor()
cursor.execute(query)
for row in cursor:
url = 'https://'+row[0]+row[1]+'api.php'
print url
wiki = wikitools.Wiki(url)
wiki.login(username,password)
page=wikitools.Page(wiki, u'User:{0}/common.js'.format(username))
try:
page.edit(text, summary='Creating global.js file',createonly=1)
time.sleep(5)
except KeyError, e:
print e
print 'Probably closed'
except wikitools.api.APIError:
print 'Already created'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment