def main(): user_list = list() tree = ET.parse(infile) # tree = ET.parse('wiki-data.xml') root = tree.getroot() for user in root[0]: data = dicto(user.attrib) # print data.Title n = User() n.id = data.ID n.name = data.Title for u in user: for u2 in u: u3 = dicto(u2.attrib) n[u3.Name] = u2.text user_list.append(n) headers = list() with open(outfile, 'wb') as f: for u in user_list: for k, v in u.items(): headers.append(k) headers = set(headers) headers = [h for h in headers] for h in headers: f.write(h + '\t') for u in user_list: f.write('\n') key_count = 0 for h in headers: if h in u.keys(): f.write(u[h] + '\t') else: f.write('\t')
def get_conbill_prices(infile): cbprices = list() infile = './data/dollar-price.csv' with open(infile) as f: lines = csv.reader(f, dialect='excel') for line in lines: p = dicto() p.brand_id = line[1] p.pack_id = line[2] p.price = line[4] p.name = line[0] cbprices.append(p) return cbprices
def main(): user_list = list() tree = ET.parse(infile) # tree = ET.parse('wiki-data.xml') root = tree.getroot() for user in root[0]: data = dicto(user.attrib) # print data.Title n = User() n.id = data.ID n.name = data.Title for u in user: for u2 in u: u3 = dicto(u2.attrib) n[u3.Name] = u2.text user_list.append(n) headers = list() with open(outfile, 'wb') as f: for u in user_list: for k, v in u.items(): headers.append(k) headers = set(headers) headers = [h for h in headers] for h in headers: f.write(h + '\t') for u in user_list: f.write('\n') key_count = 0 for h in headers: if h in u.keys(): f.write(u[h] + '\t') else: f.write('\t')
def setUp(self): # make normal dict self.value = { 'one': 1, 'two': 2, 'hello': 'world', 'tlist': [1, 2, 3], 'tdict': { '1': 'one', '2': 'two', } } # make dicto 1 using attributes self.d1 = dicto() self.d1.one = 1 self.d1.two = 2 self.d1.hello = 'world' self.d1.tlist = list([1, 2, 3]) self.d1.tdict = dict({'1': 'one', '2': 'two'}) # make dicto 2 using dict self.d2 = dicto(self.value)
def database_connection(dburi): db = dicto() db.base = Base() db.engine = create_engine(dburi) db.metadata = MetaData(bind=db.engine) db.session = Session(db.engine) db.db_session = scoped_session( sessionmaker( autocommit=True, autoflush=True, bind=db.engine ) ) db.base.query = db.db_session.query_property() from models import ConBillInvoice, ConBillProduct return db
#!/home/eburt/.virtualenvs/hdmi-rs232/bin/python from dicto import dicto ports = dicto() ports.p01 = '01010101'.decode('hex') ports.p02 = '01010102'.decode('hex') ports.p03 = '01010103'.decode('hex') ports.p04 = '01010104'.decode('hex') ports.p05 = '01010105'.decode('hex') ports.p06 = '01010106'.decode('hex') ports.p07 = '01010107'.decode('hex') ports.p08 = '01010108'.decode('hex') ports.p09 = '01010109'.decode('hex')
def color_add(): if request.method == 'GET': log.info('GET /color/add/') elif request.method == 'POST': log.info('POST /colors/add') data = dicto(request.form) data.colors = data.colors[0].split(',') # need to do some date formatting here # convert input date to iso8601 input_date = parse_date(data.date[0]) parsed_date = input_date.strftime('%Y-%m-%d') log.info('parsed date: {0}'.format(parsed_date)) day = session.query(ColorSet).filter(ColorSet.date == parsed_date).first() tmp = list() for c in data.colors: n = c.split('\r\n') for nerp in n: tmp.append(nerp) data.colors = tmp # get the correct colorset log.info('setting colorset...') # day not yet entered if day is None: log.info('new colorset') colorset = ColorSet() colorset.date = input_date # day previously entered else: log.info('found colorset') colorset = day # add colors to colorset for c in data.colors: c = c.strip() pprint(c) log.info(c) color = Color() color.name = c old_colors = [i.name for i in colorset.colors] log.debug('old colors {0}'.format(old_colors)) if c != '': # check if color already added if c not in old_colors: log.info('adding color: {0}'.format(c)) colorset.colors.append(color) else: log.warn('color {0} already entered'.format(c)) # commit changes to db log.debug(colorset.date) session.add(colorset) session.commit() form = ColorForm(csrf_enabled=False) return render_template('public/color-form.html', text='', form=form)
import json import os import sys from pprint import pprint from dicto import dicto import binascii config_file = './config.json' config_stream = open(config_file, 'rb') config = dicto(json.load(config_stream)) g510 = dicto(config.g510) # json can't handle hex # this converts the vendor and device id from str to hex g510.vendor_id = hex(int(g510.vendor_id)) g510.device_id = hex(int(g510.device_id))