Skip to content

Instantly share code, notes, and snippets.

@xZise
xZise / gist:f15235a0289f312aa61b
Created September 3, 2014 14:32
Unicode example
python pwb.py cosmetic_changes -family:bomb -lang:en-gb -page:Äöü
ATTENTION: You can run this script as a stand-alone for testing purposes.
However, the changes that are made are only minor, and other users
might get angry if you fill the version histories and watchlists with such
irrelevant changes. Some wikis prohibit stand-alone running.
Do you really want to continue? ([y]es, [N]o) y
Password for user BobBot on bomb:en-gb (no characters will be shown):
Logging in to bomb:en-gb as BobBot
Retrieving 1 pages from bomb:en-gb.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import argparse
import math
import getpass
import sys
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def test(orig, encr):
@xZise
xZise / output
Last active August 29, 2015 14:05
Rewrite the parameters to be readable by argpare
['-o', 'hello world']
['-o', 'hello world']
False
None
hello world
['-o', 'hello world', '-p:page']
['-o', 'hello world', '-p=page']
False
page
hello world
#!/usr/bin/env python
import os
import re
import subprocess
import sys
import tempfile
import shutil
import traceback
if sys.version_info[0] >= 3:
basestring = (str, )
found = -2
if args.inposition < 0:
args.inposition %= len([s for s in video.streams if s.fftype == "a"])
args.inposition += 1
i = 0
left = args.inposition
for stream in video.streams:
if stream.fftype != "v" and found < -1:
found = -1
if left == 0 and found == -1:
@xZise
xZise / update.py
Created February 12, 2014 17:18
Version update script
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Checks after an update of Kerbal Space Program if part configuration
files need to be updated, added or moved.
It first searches through the complete GameData/Squad/Parts directory
and catalogues all parts. It then compares every file with the existing
one on the wiki. If it doesn't exists, it searches for the infobox with
the part name to determine the current location on the wiki. It will
@xZise
xZise / data_template.py
Created February 12, 2014 17:14
Adding {{Data template used}}
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pywikibot
import re
from pywikibot import textlib
site = pywikibot.getSite()
data_template = re.compile(".*/(Data|Box|RefFrame|Param)")
yes_all = False
for arg in pywikibot.handleArgs():
@xZise
xZise / add_language.py
Created February 9, 2014 13:21
Script to add a language
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Automatically adds a new language to the KSP wiki. It follows
the instructions from http://wiki.kerbalspaceprogram.com/wiki/Kerbal_Space_Program_Wiki:Adding_a_New_Language :
1. Create MediaWiki:langlink-##, where ## is the two-letter language code. The content should be {{mw-langlink|##}}
2. Add {{mp-lang|##}} to Template:Main Page Layout/Language Box.
3. Add ** langlink-##|Language Name to MediaWiki:Sidebar under Languages.
4. Check the templates in Category:Language code templates if the language code needs to be added.
@xZise
xZise / gist:8729895
Last active August 29, 2015 13:55
n-body halving example
class CelestialBody {
double mass;
QVector3D position;
QVector3D velocity;
QVector3D f[];
}
PART
{
// this is a sample config file, for determining a good file format for defining part parameters
// comment line - ignored by cfg parser
// empty lines, or lines without a '=' sign are also ignored
// all other lines are split at the '=' sign, and the left operand is used to know what parameter we are setting
// diferent parameters require data in different formats (see docs), and each module has it's own parameters (again, see docs)
// each assignment must be in a single line. Lines without assignments will be ignored. (You CAN turn on word wrap, though)
// each keyword here relates to an existing variable in the assigned module. If the keyword isn't found, it is ignored.
// conversely, if a keyword is left unassigned (as in not in the file), it will be initialized with it's default value