Last active
December 18, 2015 20:48
-
-
Save azenla/5842421 to your computer and use it in GitHub Desktop.
Python KenBot API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
import urllib2 | |
import sys | |
codeCodes = { | |
'black': '0;30', 'bright gray': '0;37', | |
'blue': '0;34', 'white': '1;37', | |
'green': '0;32', 'bright blue': '1;34', | |
'cyan': '0;36', 'bright green': '1;32', | |
'red': '0;31', 'bright cyan': '1;36', | |
'purple': '0;35', 'bright red': '1;31', | |
'yellow': '0;33', 'bright purple':'1;35', | |
'dark gray':'1;30', 'bright yellow':'1;33', | |
'normal': '0' | |
} | |
def printc(text, color): | |
print "\033["+codeCodes[color]+"m"+text+"\033[0m" | |
def writec(text, color): | |
sys.stdout.write("\033["+codeCodes[color]+"m"+text+"\033[0m") | |
def switchColor(color): | |
sys.stdout.write("\033["+codeCodes[color]+"m") | |
def out(text): | |
sys.stdout.write(text) | |
def o(text, value): | |
switchColor('bright green') | |
out(text) | |
switchColor('normal') | |
out(value + '\n') | |
printc('Opening Connection to KenBot', 'blue') | |
response = urllib2.urlopen("http://107.20.249.10:7000/") | |
data = response.read() | |
response.close() | |
json = json.loads(data) | |
config = json['configuration'] | |
o('IRC Server: ', config['server']) | |
o('Nickname: ', config['user']) | |
o('Command Prefix: ', config['prefix']) | |
channels = json['channels'] | |
printc('Channels:', 'bright green') | |
count = 0 | |
for i in channels: | |
count = count + 1 | |
str = " {}. {}".format(count, i) | |
print(str) | |
printc('Done', 'blue') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment