-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathedit.py
91 lines (63 loc) · 2.53 KB
/
edit.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from os import listdir
from TradingCards import inpConf
def editTheme():
isTheme = False
themeList = listdir('themes')
themeStr = ', '.join(themeList)[0:]
usedChance = 0
validChoice = False
while not isTheme:
themeName = inpConf('{0}\nInput the exact name of the theme you are editing: '.format(themeStr))
if themeName in themeList:
isTheme = True
else:
print('Invalid theme:', themeName)
fileDir = 'themes/'+themeName+'/'
with open(fileDir+'cnames.txt', 'r') as cNameFile:
cardNames = [name.strip() for name in cNameFile.readlines()]
cardNamesL = [name.lower() for name in cardNames]
while True:
cardNamesL = [name.lower() for name in cardNames]
cardNameStr = ', '.join(cardNames)
validChoice = False
cardChoice = inpConf('(E)diting, (A)dding, or (D)eleting a card name (-- to quit): ').lower()
if cardChoice[0] == 'e':
print(cardNameStr)
nameChoice = inpConf('Which name are you editing: ')
validChoice = True
elif cardChoice[0] == 'a':
nameChoice = inpConf('Which name are you adding: ')
validChoice = True
elif cardChoice[0] == 'd':
print(cardNameStr)
nameChoice = inpConf('Which name are you deleting: ')
validChoice = True
elif cardChoice == '--':
validChoice = False
break
else:
validChoice = False
if validChoice:
if cardChoice == 'a':
if not nameChoice.lower() in cardNamesL:
cardNames.append(nameChoice)
else:
print('Card name already exists!')
elif nameChoice.lower() in cardNamesL:
nameIndex = cardNamesL.index(nameChoice.lower())
if cardChoice == 'e':
cardNames[nameIndex] = inpConf('Input card name: ')
elif cardChoice == 'd':
del cardNames[nameIndex]
else:
print('editTheme error', cardNames, nameChoice)
else:
print('Name',nameChoice,'not found.')
else:
print('Invalid input:', cardChoice)
with open(fileDir+'cnames.txt', 'w') as cNameFile:
for idx, cName in enumerate(cardNames, start = 1):
if idx < len(cardNames):
cNameFile.write(cName+'\n')
else:
cNameFile.write(cName)