Skip to content

Instantly share code, notes, and snippets.

@leMaik
Last active December 25, 2015 21:09
Show Gist options
  • Save leMaik/7040974 to your computer and use it in GitHub Desktop.
Save leMaik/7040974 to your computer and use it in GitHub Desktop.
Converter for Minecraft server ban-lists. Just put the banned-players.txt as argument and this script will convert it into a beautiful table for use in DokuWiki. Licensed under the WTFPL, so do what the f... you want to do! :-)
"""
A converter for Minecraft server ban-lists. It will convert the ugly
banned-players.txt into a beautiful table for use in DokuWiki.
Copyright (c) 2013 Maik Marschner
This program is free software; you can redistribute it and/or
modify it under the terms of the Do What The Fuck You Want To
Public License, Version 2, as published by Sam Hocevar. See
http://www.wtfpl.net/txt/copying/ for more details.
"""
import sys
import os
STR_PLAYER = 'Player' #Translation for 'Player' in the table header
STR_BANNED_ON = 'Ban date' #Translation for 'Ban date' in the table header
STR_DATE_FMT = '%Y-%m-%d' #Your custom date format, see strftime-Syntax for more information
if len(sys.argv) != 2:
print 'You must give a filename as parameter.'
sys.exit(1)
#Preparing...
filename = sys.argv[1]
banned = []
#Reading file, filling array...
try:
f = file(filename, 'r')
for line in f:
if len(line.strip()) > 0 and not line.strip().startswith('#'):
data = line.split('|')
from datetime import datetime
date = datetime.strptime(data[1].split(' ')[0], "%Y-%m-%d")
banned.append((data[0], date))
f.close()
except Exception:
print 'An error occured while reading the file.'
sys.exit(2);
try:
#Saving file...
savename = os.path.join(os.path.dirname(filename), 'banned-players-table.txt')
f = open(savename, 'w')
f.write("^ {0:25} ^ {1:10} ^\n".format(('{} ({})'.format(STR_PLAYER, len(banned))), STR_BANNED_ON))
for player in banned:
f.write("| {0:25} | {1:10} |\n".format('%%{}%%'.format(player[0]), player[1].strftime(STR_DATE_FMT)))
f.close()
print 'Beautiful table saved to {}'.format(savename)
except:
print 'An error occured while saving the file.'
sys.exit(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment