Skip to content

Commit a2bb0c7

Browse files
committed
Read tags from JSON file. #2
1 parent 31b529c commit a2bb0c7

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

TagActor.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import pykka, logging
1+
import pykka, logging, json
22
from pygame import mixer
33

4-
import data.tags as tags
4+
TAGS_FILE = 'data/tags.json'
55

66
class TagActor(pykka.ThreadingActor):
77
def __init__(self, stateActor):
@@ -16,6 +16,22 @@ def __init__(self, stateActor):
1616
def playByTag(self, tag, fromStart=False):
1717
try:
1818
self.ack.play()
19-
self.stateActor.playFromLastState(tags.tags[tag], fromStart)
19+
20+
tags = self.loadTags()
21+
print tags
22+
self.stateActor.playFromLastState(tags[tag], fromStart)
2023
except KeyError:
2124
logging.getLogger('zbap').error('No such tag %s' % tag)
25+
26+
def loadTags(self):
27+
try:
28+
with open(TAGS_FILE, 'r') as tagsFile:
29+
return json.load(tagsFile)
30+
except (IOError, ValueError) as e:
31+
logging.getLogger('zbap').error('Unable to load tag file %s' % TAGS_FILE)
32+
logging.getLogger('zbap').exception(e)
33+
return {}
34+
35+
def saveTags(self, state):
36+
with open(TAGS_FILE, 'w') as tagsFile:
37+
json.dump(state, tagsFile)

data/__init__.py

Whitespace-only changes.

data/tags.py

-4
This file was deleted.

0 commit comments

Comments
 (0)