def read_meta(self): currencies = UNITS.keys() # ['EUR', 'USD'] usecols = ','.join([self._XLSX_CONF['columns'][c] for c in currencies]) logging.debug('reading names') names = pd.read_excel(self.excel_file, skiprows=self._XLSX_CONF['rows']['names'], usecols=usecols, names=currencies, nrows=1, header=None) logging.debug('reading quantities') quantities = pd.read_excel( self.excel_file, skiprows=self._XLSX_CONF['rows']['quantity'], usecols=usecols, names=currencies, nrows=1, header=None) logging.debug('reading codes') codes = pd.read_excel(self.excel_file, skiprows=self._XLSX_CONF['rows']['code'], usecols=usecols, names=currencies, nrows=1, header=None) for c in currencies: currency_exists = self.db_session.query( exists().where(RefCurrency.code == codes[c][0])).scalar() if not currency_exists: rc = RefCurrency(name=names[c][0], quantity=quantities[c][0], code=codes[c][0]) self.db_session.add(rc) logging.debug('commiting changes') self.db_session.commit()
def index(): l = [] for k, u in UNITS.items(): l.append({'id': k, 'title': u['name']}) return {'count': 200, 'page': 1, 'results': l}
OPERATIONS = { # Operation: priority / assoc '(': (9, "L", '('), ')': (0, "R", ')'), '^': (5, "L", '^'), '*': (4, 'L', '*'), '.': (4, 'L', '*'), '/': (4, 'L', '/'), '+': (4, 'L', '+'), '-': (4, 'L', '-') } NUMBER = "0123456789E-," BOUNDARIES = OPERATIONS.keys() PREFIXES = PREFIXLIST.keys() UNITS = UNITLIST.keys() # Parser implemented as a state machine :-) # just for fun ? class ParserState(object): """ Parser base state. Contains : - src : source string (being parsed) - pos : current parsing position - stack : current result of parsing (list of ('type', 'value', pos)) """ def action(self): raise NotImplemented("Not implemented")