示例#1
0
def main():
    infile = sys.argv[1]
    outfile = os.path.splitext(infile)[0] + '.sql'

    table = tableview.load(infile)

    with open(outfile, 'w') as fp:
        for row in table:
            fp.write(row_to_sql(row) + '\n')
示例#2
0
    def load(filename, package):
        '''
        Load a pin map from a csv file.
        See the documentation for load() at the module level for more info.
        '''
        def parse_cell(s):
            s = s.lower()
            seps = '/ '
            res = [s]
            for sep in seps:
                s, res = res, []
                for seq in s:
                    res += seq.split(sep)
            return [x for x in res if x.strip()]

        table = tableview.load(filename)
        pin_map = {}
        header = table[0]
        func_cols = []
        remap_cols = []
        pin_col = None
        for i, cell in enumerate(header):
            if package.strip().lower() in cell.strip().lower():
                pin_col = i
            if "func" in cell.strip().lower():
                func_cols.append(i)
            if "remap" in cell.strip().lower():
                remap_cols.append(i)
        if pin_col == None:
            raise Exception("Couldn't find the package requested")
        for row in table:
            try:
                pin = int(row[pin_col])
            except:
                continue

            l = [parse_cell(row[i]) for i in func_cols if row[i].strip() != '']
            funcs = []
            for f in l:
                funcs.extend(f)

            l = [
                parse_cell(row[i]) for i in remap_cols if row[i].strip() != ''
            ]
            remap_funcs = []
            for f in l:
                remap_funcs.extend(f)
            pin_map[pin] = (funcs, remap_funcs)
        p = PinMap(pin_map)
        p.name = filename
        p.package = package
        return p
示例#3
0
    def load(filename, package):
        '''
        Load a pin map from a csv file.
        See the documentation for load() at the module level for more info.
        '''
        def parse_cell(s):
            s = s.lower()
            seps='/ '
            res = [s]
            for sep in seps:
                s, res = res, []
                for seq in s:
                    res += seq.split(sep)
            return [x for x in res if x.strip()]

        table = tableview.load(filename)
        pin_map = {}
        header = table[0]
        func_cols = []
        remap_cols = []
        pin_col = None
        for i, cell in enumerate(header):
            if package.strip().lower() in cell.strip().lower():
                pin_col = i
            if "func" in cell.strip().lower():
                func_cols.append(i)
            if "remap" in cell.strip().lower():
                remap_cols.append(i)
        if pin_col == None:
            raise Exception("Couldn't find the package requested")
        for row in table:
            try:
                pin = int(row[pin_col])
            except:
                continue

            l = [parse_cell(row[i]) for i in func_cols if row[i].strip() != '']
            funcs = []
            for f in l:
                funcs.extend(f)

            l = [parse_cell(row[i]) for i in remap_cols if row[i].strip() != '']
            remap_funcs = []
            for f in l:
                remap_funcs.extend(f)
            pin_map[pin] = (funcs, remap_funcs)
        p = PinMap(pin_map)
        p.name = filename
        p.package = package
        return p
    if icon not in ICONS:
    	print icon
    icons[i] = ICONS.get(icon, '_doge')
    
# Parse dates
xml_day_one = dom.getElementsByTagName('start-valid-time')[0].firstChild.nodeValue[0:10]
day_one = datetime.datetime.strptime(xml_day_one, '%Y-%m-%d')

# Parse time
now = utc.localize(datetime.datetime.utcnow())
local = pytz.timezone(TIMEZONE)
now = now.astimezone(local)
time_string = now.strftime('%I:%M').lstrip('0')

# Parse recycling schedule
schedule = tableview.load('recycling_schedule.csv')
pickup_days = set()
for row in schedule[1:]:
    year = int(row[0])
    month = int(row[1])
    days = [int(cell) for cell in row[2:] if cell]
    for day in days:
        pickup_days.add((year,month,day))
warning_days = [now + datetime.timedelta(days=n) for n in range(3)]
warning_days = [(day.year, day.month, day.day) for day in warning_days]

recycling = False
for day in warning_days:
    if day in pickup_days:
        recycling = True
示例#5
0
import json
import tableview

table = tableview.load('plants.csv', 'utf8')

keys = table[0]
output = []
for record in table[1:]:
    product = {}
    for i,key in enumerate(keys):
        product[key] = record[i]
    output.append(product)

with open('../data/catalog.js','w') as fp:
    fp.write('var products = ')
    json.dump(output, fp, sort_keys=True, indent=3)