# Path: orm.py
# def now():
# def set_sqlite_pragma(dbapi_connection, connection_record):
#     def is_blank(self):
#     def save(self):
#     def save(self):
#     def save(self):
# def counter():
# def exithandler():
# class Value(Base):
# class DataSet(Base):
# class Indicator(Base):


import re
import datetime
import requests
import orm
import logging
from orm import session, Value, DataSet, Indicator

    @property
    def combined(self):
        return [dict(zip(self.column_fieldnames, row)) for row in self.rows]

    def extract(self, fieldname):
        try:
            return [{'region': x['country'], 'value': x[fieldname]} for x in self.combined]
        except Exception:
            return [{'region': x['countries'], 'value': x[fieldname]} for x in self.combined]

    def export(self, meta):
        ind = {'indID': meta['indID'],
               'name': self.name_for_fieldname(meta['fieldname']), 
               'units': meta['unit']}
        Indicator(**ind).save()

        for item in self.extract(meta['fieldname']):
            if not item.get('region'):
                logging.warn("No region in {}".format(meta))
                continue
            value = {'dsID': dsID,
                     'region': item['region'],
                     'period': meta.get('period') or get_period(meta['fieldname']),
                     'value': item['value'],
                     'indID': meta['indID'],
                     'source': self.url,
                     'is_number': meta.get('is_number') or True}
            if value['region'] and value['value']:
                print value

# Path: orm.py
# def now():
# def set_sqlite_pragma(dbapi_connection, connection_record):
#     def is_blank(self):
#     def save(self):
#     def save(self):
#     def save(self):
# def counter():
# def exithandler():
# class Value(Base):
# class DataSet(Base):
# class Indicator(Base):


# Path: novel_undp.py
import re
import datetime
import requests
import orm
import logging
from orm import session, Value, DataSet, Indicator


    @property
    def combined(self):
        return [dict(zip(self.column_fieldnames, row)) for row in self.rows]

    def extract(self, fieldname):
        try:
            return [{'region': x['country'], 'value': x[fieldname]} for x in self.combined]
        except Exception:
            return [{'region': x['countries'], 'value': x[fieldname]} for x in self.combined]

    def export(self, meta):
        ind = {'indID': meta['indID'],
               'name': self.name_for_fieldname(meta['fieldname']), 
               'units': meta['unit']}
        Indicator(**ind).save()

        for item in self.extract(meta['fieldname']):
            if not item.get('region'):
                logging.warn("No region in {}".format(meta))
                continue
            value = {'dsID': dsID,
                     'region': item['region'],
                     'period': meta.get('period') or get_period(meta['fieldname']),
                     'value': item['value'],
                     'indID': meta['indID'],
                     'source': self.url,
                     'is_number': meta.get('is_number') or True}
            if value['region'] and value['value']:
                print value

                Value(**value).save()