def _pass_market_data(self, content: str) -> list: if content is not None: tb = self._get_table(content) if tb is not None: items = [] trs = tb.find('tbody').findAll('tr') keys = [ 'date', 'opening', 'highest', 'lowest', 'closing', 'amount', 'total_circulation', 'total' ] for tr in trs: item = {} tds = tr.findAll('td') for i in range(len(tds)): key = keys[i] text: str = tds[i].text if key == 'date': item[key] = DateTime.from_str( text, '%Y年%m月%d日', timezone_hours=0).date.timestamp elif key == 'amount' or key == 'total_circulation': item[key] = text.replace(',', '') else: item[key] = float(text) item['total'] = format( self.currency_count() * item['closing'], '.0f') items.append(item) return items return None
class NRState(object): """ 需要持久化的状态类型数据管理类(Cache & Db) """ _neb_key_last_sync_date = "neb_last_sync_date" _neb_key_market_last_sync_date = "neb_market_last_sync_date" _neb_begin_date = DateTime.from_str("20180508", "%Y%m%d", timezone_hours=0).timestamp # _neb_begin_date = DateTime.from_str("20181127", "%Y%m%d", timezone_hours=0).timestamp _eth_key_last_sync_date = "eth_last_sync_date" _eth_key_market_last_sync_date = "eth_market_last_sync_date" _eth_begin_date = DateTime.from_str("20170101", "%Y%m%d", timezone_hours=0).timestamp # neb nr date ------------------------------------------------------------------------------------------------------ @property def neb_last_sync_date(self): return self.get_last_date(self._neb_key_last_sync_date) @neb_last_sync_date.setter def neb_last_sync_date(self, value): self.set_last_date(self._neb_key_last_sync_date, value) @property def neb_current_sync_date(self): return self.get_current_date(self._neb_begin_date, self.neb_last_sync_date) # neb market date -------------------------------------------------------------------------------------------------- @property def neb_market_last_sync_date(self): d = self.get_last_date(self._neb_key_market_last_sync_date) if d == 0: d = self._neb_begin_date return d @neb_market_last_sync_date.setter def neb_market_last_sync_date(self, value): self.set_last_date(self._neb_key_market_last_sync_date, value) # eth nr date ------------------------------------------------------------------------------------------------------ @property def eth_last_sync_date(self): return self.get_last_date(self._eth_key_last_sync_date) @eth_last_sync_date.setter def eth_last_sync_date(self, value): self.set_last_date(self._eth_key_last_sync_date, value) @property def eth_current_sync_date(self): return self.get_current_date(self._eth_begin_date, self.eth_last_sync_date) # eth market date -------------------------------------------------------------------------------------------------- @property def eth_market_last_sync_date(self): d = self.get_last_date(self._eth_key_market_last_sync_date) if d == 0: d = self._eth_begin_date return d @eth_market_last_sync_date.setter def eth_market_last_sync_date(self, value): self.set_last_date(self._eth_key_market_last_sync_date, value) # private ---------------------------------------------------------------------------------------------------------- @staticmethod def get_last_date(key): ts = NRLocalMemCache.get(key) if ts is None: ts = DbStates.get(key) if ts is None: ts = 0 return ts @staticmethod def set_last_date(key, value): ts = DateTime(timestamp=value, timezone_hours=0).date.timestamp DbStates.set(key, ts) NRLocalMemCache.set(key, ts) @staticmethod def get_current_date(begin_date, last_date): if last_date == 0: return begin_date else: return DateTime(timestamp=last_date, timezone_hours=0).add_days(1).timestamp