-
Notifications
You must be signed in to change notification settings - Fork 59
/
CardList.py
39 lines (32 loc) · 949 Bytes
/
CardList.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
import csv
import os.path
import sys
class CardList:
def __init__(self):
self.path = os.path.dirname(os.path.realpath(__file__))
self.cardList = self.readList()
def readList(self):
with open(self.path + '/cardList.csv', mode='r') as infile:
reader = csv.reader(infile)
cardList = {rows[0]:rows[1] for rows in reader}
infile.close()
return cardList
def getPlaylist(self,card):
self.cardList = self.readList()
try:
return self.cardList[card]
except:
print 'Card %s is not card list' % card
return ''
def addPlaylist(self, card, plist):
try:
if card not in self.cardList.keys():
f = open(self.path + '/cardList.csv', 'a')
f.write(card + ',' + plist + '\n')
self.cardList[card] = plist
else:
print 'Card %s is already used' % card
except:
print 'Could not write file'
if not os.path.isfile(self.path + '/cardList.csv'):
print 'File cardList.csv does not exist'