def get_user_id(cls, field_name, field_value): db_conf, tb_shard = models.get_db_table(field_value) cnn = Connection(*db_conf) try: tb_name = '%s_%d' % (cls.__tablename__, tb_shard,) sql = 'SELECT `user_id` FROM `%s` WHERE `field_name`=%%s AND `field_value`=%%s' % (tb_name,) row = cnn.get(sql, field_name, field_value) return row.user_id finally: cnn.close()
def get(cls, id): db_conf, tb_shard = get_db_table(id) cnn = Connection(*db_conf) try: tb_name = '%s_%d' % (cls.__tablename__, tb_shard,) sql = 'SELECT * FROM `%s` WHERE `%s`=%%s' % (tb_name, cls.__pk__,) row = cnn.get(sql, id) return cls(**row) finally: cnn.close()
def get_user_id(cls, field_name, field_value): db_conf, tb_shard = models.get_db_table(field_value) cnn = Connection(*db_conf) try: tb_name = '%s_%d' % ( cls.__tablename__, tb_shard, ) sql = 'SELECT `user_id` FROM `%s` WHERE `field_name`=%%s AND `field_value`=%%s' % ( tb_name, ) row = cnn.get(sql, field_name, field_value) return row.user_id finally: cnn.close()
def get(cls, id): db_conf, tb_shard = get_db_table(id) cnn = Connection(*db_conf) try: tb_name = '%s_%d' % ( cls.__tablename__, tb_shard, ) sql = 'SELECT * FROM `%s` WHERE `%s`=%%s' % ( tb_name, cls.__pk__, ) row = cnn.get(sql, id) return cls(**row) finally: cnn.close()
def get(self, feed_type_id): fields = ['feed_id', 'url', 'feed_type_id', 'symbol_type_id'] # get all available feeds of provided type feeds = Connection.get(self, query_params={ 'tablename': 'feed', 'fields': fields, 'where_stmt': [{ 'key': 'feed_type_id', 'value': feed_type_id }] }) # loop feeds, create a new feed class, # and associate with a symbol type class for use in entity processing for feed in feeds: values = dict(zip(fields, list(feed))) new_feed = Feed(**values) new_feed.symbol_type_class = self.symbol_type_class_mapping[ new_feed.symbol_type_id] self.feeds.append(new_feed)
def get(self, symbol_type_id): fields = [ 'symbol_id', 'symbol_type_id', 'symbol', 'name', 'full_name', 'meta', ] symbols = Connection.get(self, query_params={ 'tablename': 'symbol', 'fields': fields, 'where_stmt': [{ 'key': 'symbol_type_id', 'value': symbol_type_id }] }) for symbol in symbols: values = dict(zip(fields, list(symbol))) self.symbols.append(Symbol(**values))
def __init__(self): Connection.__init__(self) exchanges = self.get_exchanges() for exchange in exchanges: source = self.request_source(exchange[2]) symbol_exchange_rates = json.loads(source) for sym in symbol_exchange_rates: # TODO: Load correct endpoint field names by exchange args = { 'tablename': 'symbol', 'conditional': 'AND', 'where_stmt': [{ 'key': 'symbol', 'value': sym['symbol'], 'operator': '=' }, { 'key': 'symbol_type_id', 'value': exchange[1], 'operator': '=' }] } exists = Connection.exists(self, args) # Add symbol to table if it does not exist. if (not exists): Connection.set(self, query_params={ 'tablename': 'symbol', 'fields': { 'symbol_type_id': exchange[1], 'symbol': sym['symbol'], 'name': sym['id'], 'meta': '', 'full_name': sym['name'] } }) # Get our symbol id # TODO: We need to grab this symbol id from an object cache. # See https://trello.com/c/nivVoxpF symbol_id = Connection.get(self, query_params={ 'tablename': 'symbol', 'where_stmt': [{ 'key': 'symbol', 'value': sym['symbol'], 'operator': '=' }, { 'key': 'symbol_type_id', 'value': exchange[1], 'operator': '=' }], 'fields': ['symbol_id'] }) # Insert most recent exchange rate. if (sym['last_updated']): Connection.set( self, query_params={ 'tablename': 'symbol_exchange_rate_lookup', 'fields': { 'exchange_id': exchange[0], 'symbol_id': symbol_id[0][0], 'rate': sym['price_usd'], 'date': Connection.convert_timestamp_to_datetime( self, sym['last_updated']) } })