예제 #1
0
파일: virtdb.py 프로젝트: SergeVL/petlsql
 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)
예제 #2
0
파일: virtdb.py 프로젝트: SergeVL/petlsql
 def namedtuples(self, sql):
     try:
         if isinstance(sql, str):
             sql = execute(sql, self)
         return etl.namedtuples(sql)
     except SQLError as e:
         print(e)
예제 #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)
예제 #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)
예제 #5
0
파일: test_util.py 프로젝트: brutimus/petl
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)
예제 #6
0
파일: test_util.py 프로젝트: brutimus/petl
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)
예제 #7
0
파일: test_util.py 프로젝트: talwai/petl
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)
예제 #8
0
파일: test_util.py 프로젝트: talwai/petl
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)
예제 #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()
##############
예제 #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)
예제 #11
0
파일: base.py 프로젝트: rogerkwoodley/petl
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)

예제 #12
0
파일: run.py 프로젝트: SergeVL/petlsql
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])