-
Notifications
You must be signed in to change notification settings - Fork 0
/
P2SpongeCase.py
56 lines (49 loc) · 1.62 KB
/
P2SpongeCase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from subprocess import check_call
from sys import platform, argv
from random import randint
from os import path
def copy_to_clip(string):
if(platform == 'darwin'):
cmd='echo \"' + string.strip()+'\" | pbcopy'
else:
cmd='echo \"' + string.strip()+'\" | clip'
return check_call(cmd, shell=True)
def convert_to_spongecase(text):
userInput = text.lower()
spongeString = ""
for i in range(0,len(userInput)):
if not userInput[i].isalpha():
spongeString = spongeString + userInput[i]
continue
if(randint(0,100) > 50):
spongeString = spongeString + userInput[i].upper()
else:
spongeString = spongeString + userInput[i]
return spongeString
firstLoop = False
while(1):
userInput = ""
if(len(argv) == 2 and not firstLoop):
userInput = argv[1]
firstLoop = True
else:
userInput = raw_input('Enter the string or file name to switch to sponge case. Ctrl + C or "!exit!" to quit program.\n')
spongeString = ""
if(userInput == '!exit!'):
exit()
if(path.isfile(userInput)):
inputFile = open(userInput, "r")
spongeString = convert_to_spongecase(inputFile.read())
inputFile.close()
newFile = open(path.splitext(userInput)[0] + '_spongeCase.txt', "w+")
newFile.write(spongeString)
newFile.close()
else:
spongeString = convert_to_spongecase(userInput)
print spongeString
try:
copy_to_clip(spongeString)
print "*Sponge case (probably) copied to clipboard.*"
except:
continue
#do nothing