# Path: xml2dict.py
# class XML2Dict(object):
#     @classmethod
#     def _parse_node(self, node):
#         node_tree = object_dict()
#         # Save attrs and text, hope there will not be a child with same name
#         if node.text:
#             node_tree.value = node.text
#         for (k, v) in node.attrib.items():
#             k, v = self._namespace_split(k, object_dict({'value':v}))
#             node_tree[k] = v
#         # Save childrens
#         for child in iter(node):
#             tag, tree = self._namespace_split(child.tag, self._parse_node(child))
#             if  tag not in node_tree:  # the first time, so store it in dict
#                 node_tree[tag] = tree
#                 continue
#             old = node_tree[tag]
#             if not isinstance(old, list):
#                 node_tree.pop(tag)
#                 node_tree[tag] = [old]  # multi times, so change old dict to a list
#             node_tree[tag].append(tree)  # add the new one
# 
#         return  node_tree
# 
#     @classmethod
#     def _namespace_split(self, tag, value):
#         """
#            Split the tag  '{http://cs.sfsu.edu/csc867/myscheduler}patients'
#              ns = http://cs.sfsu.edu/csc867/myscheduler
#              name = patients
#         """
#         result = re.compile("\{(.*)\}(.*)").search(tag)
#         if result:
#             # print(tag)
#             value.namespace, tag = result.groups()
#         return (tag, value)
# 
#     @classmethod
#     def parse(self, file):
#         """parse a xml file to a dict"""
#         f = open(file, 'r')
#         return self.fromstring(f.read())
# 
#     @classmethod
#     def fromstring(self, s):
#         """parse a string"""
#         t = ET.fromstring(s)
#         root_tag, root_tree = self._namespace_split(t.tag, self._parse_node(t))
#         return object_dict({root_tag: root_tree})


import os
import os.path as opath
import time
import random
import httplib2
import sys
import glob
import maclient_player
import maclient_network
import maclient_update
import maclient_smart
from xml2dict import XML2Dict

from __future__ import print_function
sys.path.append(os.path.abspath('..'))
os.chdir(os.path.abspath('..'))
sys.path[0] = os.path.abspath('.')
sys.path[0] = os.path.abspath('.')
CARD_NORM, CARD_MAX, CARD_NORM_HOLO, CARD_MAX_HOLO = 0, 1, 2, 3
ht = httplib2.Http()

reload(sys)
sys.setdefaultencoding('utf-8')

loc = ''

def gen_list(loc):
    playdata = (glob.glob('.%s-*.playerdata' % loc) + glob.glob('z:/temp/.%s-*.playerdata' % loc))[-1]
    print(playdata)

# Path: xml2dict.py
# class XML2Dict(object):
#     @classmethod
#     def _parse_node(self, node):
#         node_tree = object_dict()
#         # Save attrs and text, hope there will not be a child with same name
#         if node.text:
#             node_tree.value = node.text
#         for (k, v) in node.attrib.items():
#             k, v = self._namespace_split(k, object_dict({'value':v}))
#             node_tree[k] = v
#         # Save childrens
#         for child in iter(node):
#             tag, tree = self._namespace_split(child.tag, self._parse_node(child))
#             if  tag not in node_tree:  # the first time, so store it in dict
#                 node_tree[tag] = tree
#                 continue
#             old = node_tree[tag]
#             if not isinstance(old, list):
#                 node_tree.pop(tag)
#                 node_tree[tag] = [old]  # multi times, so change old dict to a list
#             node_tree[tag].append(tree)  # add the new one
# 
#         return  node_tree
# 
#     @classmethod
#     def _namespace_split(self, tag, value):
#         """
#            Split the tag  '{http://cs.sfsu.edu/csc867/myscheduler}patients'
#              ns = http://cs.sfsu.edu/csc867/myscheduler
#              name = patients
#         """
#         result = re.compile("\{(.*)\}(.*)").search(tag)
#         if result:
#             # print(tag)
#             value.namespace, tag = result.groups()
#         return (tag, value)
# 
#     @classmethod
#     def parse(self, file):
#         """parse a xml file to a dict"""
#         f = open(file, 'r')
#         return self.fromstring(f.read())
# 
#     @classmethod
#     def fromstring(self, s):
#         """parse a string"""
#         t = ET.fromstring(s)
#         root_tag, root_tree = self._namespace_split(t.tag, self._parse_node(t))
#         return object_dict({root_tag: root_tree})


# Path: utils/download_full.py
import os
import os.path as opath
import time
import random
import httplib2
import sys
import glob
import maclient_player
import maclient_network
import maclient_update
import maclient_smart
from xml2dict import XML2Dict

from __future__ import print_function
sys.path.append(os.path.abspath('..'))
os.chdir(os.path.abspath('..'))
sys.path[0] = os.path.abspath('.')
sys.path[0] = os.path.abspath('.')
CARD_NORM, CARD_MAX, CARD_NORM_HOLO, CARD_MAX_HOLO = 0, 1, 2, 3
ht = httplib2.Http()

reload(sys)
sys.setdefaultencoding('utf-8')

loc = ''

def gen_list(loc):
    playdata = (glob.glob('.%s-*.playerdata' % loc) + glob.glob('z:/temp/.%s-*.playerdata' % loc))[-1]
    print(playdata)

    p = maclient_player.player(XML2Dict().fromstring(open(playdata).read()).response, loc)
