Пример #1
0
 def set_syntax_tree(self):
     Connection.set(self,
                    query_params={
                        'tablename': 'entity_syntax',
                        'fields': {
                            'entity_id': self.id,
                            'pos': pos,
                            'word': word,
                            'distance_measure_string':
                            distance_measure_string
                        }
                    })
    def set_relationship(self, entity, search_text):
        for coin in self.symbols:
            # Compile regex
            regex = re.compile(
                self.pattern.substitute(
                    fullNameLower=coin.full_name.lower(),
                    fullNameTitle=coin.full_name.title(),
                    symbolLower=coin.symbol.lower(),
                    symbolUpper=coin.symbol.upper()
                ),
                re.S
            )
            # Search provided text for symbols
            result = regex.search(search_text)

            if (result):
                # set relationship between entity_id and symbol_id, if found
                Connection.set(self, query_params={
                    'tablename': 'entity_symbol_lookup',
                    'fields': {
                        'entity_id': entity.id,
                        'symbol_id': coin.symbol_id,
                    }
                })
Пример #3
0
 def set(self):
     entity_id = Connection.set(
         self,
         query_params={
             'tablename': 'entity',
             'returning': ['entity_id'],
             'fields': {
                 'title': self.title,
                 'url': self.url,
                 'publish_date': self.date,
                 'description': self.description,
                 'meta_data': json.dumps(self.metadata),
                 'syntax_tree': json.dumps(self.syntax_tree),
                 'entity_type_id':
                 0,  # @todo make this a real entity type ID
             }
         })
     print entity_id[0]
     self.id = entity_id[0]
Пример #4
0
    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'])
                            }
                        })