Last active
December 22, 2015 20:19
-
-
Save adepasquale/6525312 to your computer and use it in GitHub Desktop.
Ever hda a Skyp friendw ho loves typos?
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
from random import random, choice | |
import sys | |
import Skype4Py | |
class Tanawifiew: | |
# error probabilities: | |
p_reorder = 0.01 # wrong key order | |
p_miss_key = 0.03 # no key press | |
p_near_key = 0.005 # near key press | |
# map of the keyboard | |
near_keys = { | |
'a': ['q','w','s','z'], | |
'b': ['v','g','h','n'], | |
'c': ['x','d','f','v'], | |
'd': ['s','e','r','f','c','x'], | |
'e': ['r','d','f','w'], | |
'f': ['d','r','t','g','v','c'], | |
'g': ['f','t','y','h','b','v'], | |
'h': ['g','y','u','j','n','b'], | |
'i': ['o','k','j','u'], | |
'j': ['h','u','i','k','m','n'], | |
'k': ['j','i','o','l','m'], | |
'l': ['k','o','p'], | |
'm': ['n','j','k'], | |
'n': ['b','h','j','m'], | |
'o': ['p','l','k','i'], | |
'p': ['l','o'], | |
'q': ['w','s','a'], | |
'r': ['t','f','d','e'], | |
's': ['a','w','e','d','x','z'], | |
't': ['y','g','f','r'], | |
'u': ['i','j','h','y'], | |
'v': ['c','f','g','b'], | |
'w': ['e','s','a','q'], | |
'x': ['z','s','d','c'], | |
'y': ['u','h','g','t'], | |
'z': ['a','s','x'], | |
} | |
def process(self, message): | |
i = 0 | |
output = "" | |
# process the string | |
while i < len(message): | |
p = random() | |
if p < self.p_reorder: | |
if (i < len(message)-1): | |
output += message[i+1] + message[i] | |
i += 1 | |
elif p < self.p_miss_key + self.p_reorder: | |
pass # do nothing | |
elif p < self.p_near_key + self.p_miss_key + self.p_reorder: | |
if message[i] in self.near_keys: | |
output += choice(self.near_keys[message[i]]) | |
else: | |
output += message[i] | |
i += 1 | |
return output | |
if __name__ == "__main__": | |
f = "skype_nickname" | |
t = Tanawifiew() | |
s = Skype4Py.Skype() | |
s.Attach() # API auth request | |
while True: | |
l = sys.stdin.readline() | |
if not l: | |
break | |
m = t.process(l) | |
s.SendMessage(f, m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment