Skip to content

Instantly share code, notes, and snippets.

View tobias47n9e's full-sized avatar

Tobias Schönberg tobias47n9e

View GitHub Profile
import pywikibot
from pywikibot import pagegenerators as pg
from pywikibot import textlib
def list_template_usage(site_obj, tmpl_name):
"""
Takes Site object and template name and returns a generator.
The function expects a Site object (pywikibot.Site()) and
a template name (String). It creates a list of all
@tobias47n9e
tobias47n9e / python wikitable creator.py
Last active October 9, 2015 13:44
Create wikitables from lists in python. The function can handle highlighting of first/last row/column and can get different table classes (e.g wikitable sortable) and styles.
def create_table_string(data, highlight=(True, False, False, False),
table_class='wikitable', style=''):
"""
Takes a list and returns a wikitable.
@param data: The list that is converted to a wikitable.
@type data: List (Nested)
@param highlight: Tuple of rows and columns that should be highlighted.
(first row, last row, left column, right column)
@type highlight: Tuple
@tobias47n9e
tobias47n9e / pygobject_dnd_json
Created April 25, 2015 16:22
PyGobject drag and drop using JSON - bug with drag-data-delete signal
from gi.repository import Gtk, Gdk
import json
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="TreeView Drag and Drop")
self.connect("delete-event", Gtk.main_quit)
self.set_border_width(10)
self.set_default_size(400, 300)
@tobias47n9e
tobias47n9e / gist:1c85a746acd63d9c6142
Created March 21, 2015 22:06
Combining two lists (explanatory debug prints)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Creates a List of Player Matchups in a Tournament"""
def get_matches(players):
new_list = []
for index, name in enumerate(players):
print("====================================================")
print("Entering the 1st for-loop for the {0} time.".format(index))
@tobias47n9e
tobias47n9e / gist:3f25207e5ad77bf75482
Created March 21, 2015 21:36
Grouping two lists using enumerate and index comparisions
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Creates a List of Player Matchups in a Tournament"""
def get_matches(players):
new_list = []
for index, name in enumerate(players):
for index2, name2 in enumerate(players):
if index2 < index:
def lex(analyze):
lines = ''
listin = ()
analyze.split('\n')
analyze.split()
for i in analyze:
lines += i
lisntin.append(lines)
return len(listin)
@tobias47n9e
tobias47n9e / polar_curve
Created February 17, 2015 10:26
Plotting a curved line in a polar plot in Matplotlib
#Plotting a curved line in a polar plot in Matplotlib
import matplotlib.pylab as plt
import numpy as np
a = 0
b = 2
r1 = 2
r2 = 2
steps = 30
@tobias47n9e
tobias47n9e / gist:88f14694cc11273727a5
Created January 29, 2015 11:11
Glade interface file: Dialog window with notebook with filechooser widget
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkDialog" id="dialog1">
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
@tobias47n9e
tobias47n9e / gist:f6b38748572903a17078
Created January 29, 2015 08:48
Glade interface file: Window with notebook with filechooser widget
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
<property name="can_focus">True</property>
@tobias47n9e
tobias47n9e / remove_multiple_error
Created January 13, 2015 16:58
Non-working example to remove multiple rows from a Gtk TreeView
data_selection = data_treeview.get_selection()
data_model, data_row_list = data_selection.get_selected_rows()
treeiter_list = []
for treepath in data_row_list:
row = data_model[treepath]
treeiter_list.append(data_model.get_iter(row))
for treeiter in reversed(treeiter_list):
data_treestore.remove(treeiter)