# Path: helpers/config.py
# def load_config():
#     """ Load configuration and set debug flag for this environment """
#     
#     # Load global configuration
#     config = yaml.load(open(os.path.abspath('./conf/global.yaml'), 'r').read())
# 
#     # Detect development or production environment and configure accordingly
#     if os.environ['SERVER_SOFTWARE'].startswith('Dev'):
#         conf_f = open(os.path.abspath('./conf/development.yaml'), 'r')
#         config = dict(config.items() + yaml.load(conf_f.read()).items())
#     else:
#         conf_f = open(os.path.abspath('./conf/production.yaml'), 'r')
#         config = dict(config.items() + yaml.load(conf_f.read()).items())
# 
#     return config
# 
# class ConfigurationError(Exception):
#     """ A general configuration exception """
#     def __init__(self, value):
#         self.value = value
# 
#     def __str__(self):
#         return self.value


import httplib2
import re
import logging
import unicodedata
import base64
import xml.etree.ElementTree as ET
from datetime import datetime as dt
from helpers.config import load_config, ConfigurationError
from oauth2client.client import OAuth2WebServerFlow, OAuth2Credentials
from oauth2client.anyjson import simplejson as json
from apiclient.discovery import build

        # XML Prefixes
        atom    = '{http://www.w3.org/2005/Atom}'
        search  = '{http://a9.com/-/spec/opensearchrss/1.0/}'
        gs      = '{http://schemas.google.com/spreadsheets/2006}'

        # Format spreadsheet data
        data = {
            'key':           spreadsheet_key,
            'title':         _val(feed.find('%stitle' % atom).text),
            'updated':       _val(feed.find('%supdated' % atom).text),
            'total_results': _val(feed.find('%stotalResults' % search).text),
            'start_index':   _val(feed.find('%sstartIndex' % search).text),
            'author': {
                'name':      _val(feed.find('.//%sname' % atom).text),
                'email':     _val(feed.find('.//%semail' % atom).text),
            },
            'worksheets':    [],
        }
        
        # Format worksheet data
        for entry in feed.findall('%sentry' % atom):
            worksheet = {
                'id':        re.sub('^.*full/','',entry.find('%sid' % atom).text),
                'title':     _val(entry.find('%stitle' % atom).text),
                'updated':   _val(entry.find('%supdated' % atom).text),
                'row_count': _val(entry.find('%srowCount' % gs).text),
                'col_count': _val(entry.find('%scolCount' % gs).text),
            }
            data['worksheets'].append(worksheet)

# Path: helpers/config.py
# def load_config():
#     """ Load configuration and set debug flag for this environment """
#     
#     # Load global configuration
#     config = yaml.load(open(os.path.abspath('./conf/global.yaml'), 'r').read())
# 
#     # Detect development or production environment and configure accordingly
#     if os.environ['SERVER_SOFTWARE'].startswith('Dev'):
#         conf_f = open(os.path.abspath('./conf/development.yaml'), 'r')
#         config = dict(config.items() + yaml.load(conf_f.read()).items())
#     else:
#         conf_f = open(os.path.abspath('./conf/production.yaml'), 'r')
#         config = dict(config.items() + yaml.load(conf_f.read()).items())
# 
#     return config
# 
# class ConfigurationError(Exception):
#     """ A general configuration exception """
#     def __init__(self, value):
#         self.value = value
# 
#     def __str__(self):
#         return self.value


# Path: helpers/google_api.py
import httplib2
import re
import logging
import unicodedata
import base64
import xml.etree.ElementTree as ET
from datetime import datetime as dt
from helpers.config import load_config, ConfigurationError
from oauth2client.client import OAuth2WebServerFlow, OAuth2Credentials
from oauth2client.anyjson import simplejson as json
from apiclient.discovery import build


        # XML Prefixes
        atom    = '{http://www.w3.org/2005/Atom}'
        search  = '{http://a9.com/-/spec/opensearchrss/1.0/}'
        gs      = '{http://schemas.google.com/spreadsheets/2006}'

        # Format spreadsheet data
        data = {
            'key':           spreadsheet_key,
            'title':         _val(feed.find('%stitle' % atom).text),
            'updated':       _val(feed.find('%supdated' % atom).text),
            'total_results': _val(feed.find('%stotalResults' % search).text),
            'start_index':   _val(feed.find('%sstartIndex' % search).text),
            'author': {
                'name':      _val(feed.find('.//%sname' % atom).text),
                'email':     _val(feed.find('.//%semail' % atom).text),
            },
            'worksheets':    [],
        }
        
        # Format worksheet data
        for entry in feed.findall('%sentry' % atom):
            worksheet = {
                'id':        re.sub('^.*full/','',entry.find('%sid' % atom).text),
                'title':     _val(entry.find('%stitle' % atom).text),
                'updated':   _val(entry.find('%supdated' % atom).text),
                'row_count': _val(entry.find('%srowCount' % gs).text),
                'col_count': _val(entry.find('%scolCount' % gs).text),
            }
            data['worksheets'].append(worksheet)

        return data