Skip to content

Instantly share code, notes, and snippets.

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:
#!/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, )
@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/python
# -*- coding: utf-8 -*-
import argparse
import math
import getpass
import sys
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def test(orig, encr):
@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.
@xZise
xZise / gist:43407277407c4aa33dd9
Created November 16, 2014 22:16
BFS for iw prefix path
def interwiki_prefix_path(self, site, max_depth=2):
# all sites already checked
visited = set()
old_queue = [(self, [])]
new_queue = []
for depth in range(max_depth):
print('D{}'.format(depth))
print('Q{}'.format(old_queue))
for checked_site, path in old_queue:
print('-' * 30)
@xZise
xZise / gist:75c482a5871f0b1cb55b
Last active August 29, 2015 14:11
Parser for advanced argparse values
#!/usr/bin/python
# -*- coding: utf-8 -*-
from collections import OrderedDict
def parse_value(value, parameters, allow_unknown=False):
"""
Parse the value of an argument into subarguments.
The value is basically a comma-separated string. Each comma-separated value
can be named which is separated by an equals sign. It is possible to escape
@xZise
xZise / by-len.txt
Last active August 29, 2015 14:12
Line length analysis for ad6920135ef015855724ac660fa0dcfb1459cfda
Lines (line number in brackets) sorted for length
pywikibot/site.py 137 (l 3959)
pywikibot/site.py 126 (l 3958)
pywikibot/site.py 110 (l 3963)
pywikibot/site.py 108 (l 4458)
pywikibot/site.py 106 (l 588)
pywikibot/site.py 101 (l 3960)
pywikibot/site.py 095 (l 4380)
pywikibot/site.py 095 (l 4507)
@xZise
xZise / branch-status.py
Last active August 29, 2015 14:12
Remove branches which have been merged
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Clean up the git branches by removing branches whose change-id got merged."""
from __future__ import unicode_literals
import argparse
import collections
import itertools
import json
import re
@xZise
xZise / convert.py
Created January 12, 2015 12:02
Convert PCRE regex into Python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import sys
if sys.version_info[0] > 2:
unichr = chr
def make_compatible(src):
delim = src[0]