Exemplo n.º 1
0
 def one_record(self, sql):
     try:
         if isinstance(sql, str):
             sql = execute(sql, self)
         return next(iter(etl.namedtuples(sql)))
     except SQLError as e:
         print(e)
Exemplo n.º 2
0
 def namedtuples(self, sql):
     try:
         if isinstance(sql, str):
             sql = execute(sql, self)
         return etl.namedtuples(sql)
     except SQLError as e:
         print(e)
Exemplo n.º 3
0
def test_namedtuples_unevenrows():
    table = (('foo', 'bar'), ('a', 1, True), ('b', ))
    actual = namedtuples(table)
    it = iter(actual)
    o = it.next()
    eq_('a', o.foo)
    eq_(1, o.bar)
    o = it.next()
    eq_('b', o.foo)
    eq_(None, o.bar)
Exemplo n.º 4
0
def test_namedtuples():
    table = (('foo', 'bar'), ('a', 1), ('b', 2))
    actual = namedtuples(table)
    it = iter(actual)
    o = it.next()
    eq_('a', o.foo)
    eq_(1, o.bar)
    o = it.next()
    eq_('b', o.foo)
    eq_(2, o.bar)
Exemplo n.º 5
0
def test_namedtuples_unevenrows():
    table = (('foo', 'bar'), ('a', 1, True), ('b',))
    actual = namedtuples(table)
    it = iter(actual)
    o = it.next()
    eq_('a', o.foo)
    eq_(1, o.bar)
    o = it.next()
    eq_('b', o.foo)
    eq_(None, o.bar)
Exemplo n.º 6
0
def test_namedtuples():
    table = (('foo', 'bar'), ('a', 1), ('b', 2))
    actual = namedtuples(table)
    it = iter(actual)
    o = it.next()
    eq_('a', o.foo)
    eq_(1, o.bar)
    o = it.next()
    eq_('b', o.foo)
    eq_(2, o.bar)
Exemplo n.º 7
0
def test_namedtuples_unevenrows():
    table = (("foo", "bar"), ("a", 1, True), ("b",))
    actual = namedtuples(table)
    it = iter(actual)
    o = it.next()
    eq_("a", o.foo)
    eq_(1, o.bar)
    o = it.next()
    eq_("b", o.foo)
    eq_(None, o.bar)
Exemplo n.º 8
0
def test_namedtuples():
    table = (("foo", "bar"), ("a", 1), ("b", 2))
    actual = namedtuples(table)
    it = iter(actual)
    o = it.next()
    eq_("a", o.foo)
    eq_(1, o.bar)
    o = it.next()
    eq_("b", o.foo)
    eq_(2, o.bar)
Exemplo n.º 9
0
# dicts()
#########

import petl as etl
table = [['foo', 'bar'], ['a', 1], ['b', 2]]
d = etl.dicts(table)
d
list(d)

# namedtuples()
###############

import petl as etl
table = [['foo', 'bar'], ['a', 1], ['b', 2]]
d = etl.namedtuples(table)
d
list(d)

# records()
###############

import petl as etl
table = [['foo', 'bar'], ['a', 1], ['b', 2]]
d = etl.records(table)
d
list(d)

# rowgroupby()
##############
Exemplo n.º 10
0
locationxmlfile = './datafiles/Vic_Locations.xml'
mergedcsvfile = './datafiles/practice_locations.csv'

# xmlfields is a dictionary to be used as 

xmlfields = {'Town_name': 'Town', 'Latitude': 'Lat', 'Longitude': 'Lon'}  # type: Dict[str, str]
xmlparent = 'Town_location'
initialrow = ['Practice_Name', 'Latitude', 'Longitude', 'Town', 'State', 'Post_Code']

# tables in memory created from xml and csv files

csvtable = petl.fromcsv(healthcsvfile)
xmltable = petl.fromxml(locationxmlfile, xmlparent, xmlfields)

# Find the row in xmltable matching town from csv 
lktbl = petl.lookupone(xmltable, 'Town_name')  # type: Union[Dict[Any, Union[tuple[Any], Tuple[Any]]], Any]
nmdtbl = petl.namedtuples(csvtable)
finaltabl = [initialrow]

for lin in nmdtbl:
    tabl = lktbl[lin.Town]
    latitude = tabl[0]
    longitude = tabl[1]

    insertline = (str(lin.Practice_Name) + ',' + latitude + ',' + longitude + ',' + str(
        lin.Town) + ',' + str(lin.State) + ',' + str(lin.Postcode)).split(',')
    print insertline
    finaltabl.extend([insertline])

petl.tocsv(finaltabl, mergedcsvfile)
Exemplo n.º 11
0
import petl as etl

table = [["foo", "bar"], ["a", 1], ["b", 2]]
d = etl.dicts(table)
d
list(d)


# namedtuples()
###############

import petl as etl

table = [["foo", "bar"], ["a", 1], ["b", 2]]
d = etl.namedtuples(table)
d
list(d)


# records()
###############

import petl as etl

table = [["foo", "bar"], ["a", 1], ["b", 2]]
d = etl.records(table)
d
list(d)

Exemplo n.º 12
0
def aggregate_execute(c, header, aggregates, **kwargs):
    rows = list(iter(etl.namedtuples(c())))
    data = [f(rows) for f in aggregates]
    return etl.wrap([header, data])