Ejemplo n.º 1
0
 def get_ops(self, start=None, stop=None, use_block_num=True, only_ops=[], exclude_ops=[]):
     """ Returns ops in the given range"""
     if start is not None:
         start = addTzInfo(start)
     if stop is not None:
         stop = addTzInfo(stop)
     for op in self:
         if use_block_num and start is not None and isinstance(start, int):
             if op["block"] < start:
                 continue
         elif not use_block_num and start is not None and isinstance(start, int):
             if op["index"] < start:
                 continue
         elif start is not None and isinstance(start, (datetime, date, time)):
             if start > formatTimeString(op["timestamp"]):
                 continue
         if use_block_num and stop is not None and isinstance(stop, int):
             if op["block"] > stop:
                 continue
         elif not use_block_num and stop is not None and isinstance(stop, int):
             if op["index"] > stop:
                 continue
         elif stop is not None and isinstance(stop, (datetime, date, time)):
             if stop < formatTimeString(op["timestamp"]):
                 continue
         if exclude_ops and op["type"] in exclude_ops:
             continue
         if not only_ops or op["type"] in only_ops:
             yield op
Ejemplo n.º 2
0
 def search(self, search_str, start=None, stop=None, use_block_num=True):
     """ Returns ops in the given range"""
     ops = []
     if start is not None:
         start = addTzInfo(start)
     if stop is not None:
         stop = addTzInfo(stop)
     for op in self:
         if use_block_num and start is not None and isinstance(start, int):
             if op["block"] < start:
                 continue
         elif not use_block_num and start is not None and isinstance(start, int):
             if op["index"] < start:
                 continue
         elif start is not None and isinstance(start, (datetime, date, time)):
             if start > formatTimeString(op["timestamp"]):
                 continue
         if use_block_num and stop is not None and isinstance(stop, int):
             if op["block"] > stop:
                 continue
         elif not use_block_num and stop is not None and isinstance(stop, int):
             if op["index"] > stop:
                 continue
         elif stop is not None and isinstance(stop, (datetime, date, time)):
             if stop < formatTimeString(op["timestamp"]):
                 continue
         op_string = json.dumps(list(op.values()))
         if re.search(search_str, op_string):
             ops.append(op)
     return ops
Ejemplo n.º 3
0
 def test_formatDateTimetoTimeStamp(self):
     t = "1970-01-01T00:00:00"
     t = formatTimeString(t)
     timestamp = formatToTimeStamp(t)
     self.assertEqual(timestamp, 0)
     t2 = "2018-07-10T10:08:39"
     timestamp = formatToTimeStamp(t2)
     self.assertEqual(timestamp, 1531217319)
     t3 = datetime(2018, 7, 10, 10, 8, 39)
     timestamp = formatToTimeStamp(t3)
     self.assertEqual(timestamp, 1531217319)
Ejemplo n.º 4
0
 def test_history(self):
     account = self.account
     zero_element = 0
     h_all_raw = []
     for h in account.history_reverse(raw_output=True):
         h_all_raw.append(h)
     # h_all_raw = h_all_raw[zero_element:]
     zero_element = h_all_raw[-1][0]
     h_list = []
     for h in account.history(stop=10,
                              use_block_num=False,
                              batch_size=10,
                              raw_output=True):
         h_list.append(h)
     # self.assertEqual(h_list[0][0], zero_element)
     self.assertEqual(h_list[-1][0], 10)
     self.assertEqual(h_list[0][1]['block'], h_all_raw[-1][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-11 + zero_element][1]['block'])
     h_list = []
     for h in account.history(start=1,
                              stop=9,
                              use_block_num=False,
                              batch_size=10,
                              raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 1)
     self.assertEqual(h_list[-1][0], 9)
     self.assertEqual(h_list[0][1]['block'],
                      h_all_raw[-2 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-10 + zero_element][1]['block'])
     start = formatTimeString(h_list[0][1]["timestamp"])
     stop = formatTimeString(h_list[-1][1]["timestamp"])
     h_list = []
     for h in account.history(start=start,
                              stop=stop,
                              use_block_num=False,
                              batch_size=10,
                              raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 1)
     self.assertEqual(h_list[-1][0], 9)
     self.assertEqual(h_list[0][1]['block'],
                      h_all_raw[-2 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-10 + zero_element][1]['block'])
     h_list = []
     for h in account.history_reverse(start=10,
                                      stop=0,
                                      use_block_num=False,
                                      batch_size=10,
                                      raw_output=False):
         h_list.append(h)
     # zero_element = h_list[-1]['index']
     self.assertEqual(h_list[0]['index'], 10)
     # self.assertEqual(h_list[-1]['index'], zero_element)
     self.assertEqual(h_list[0]['block'],
                      h_all_raw[-11 + zero_element][1]['block'])
     self.assertEqual(h_list[-1]['block'], h_all_raw[-1][1]['block'])
     h_list = []
     for h in account.history_reverse(start=9,
                                      stop=1,
                                      use_block_num=False,
                                      batch_size=10,
                                      raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 9)
     self.assertEqual(h_list[-1][0], 1)
     self.assertEqual(h_list[0][1]['block'],
                      h_all_raw[-10 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-2 + zero_element][1]['block'])
     start = formatTimeString(h_list[0][1]["timestamp"])
     stop = formatTimeString(h_list[-1][1]["timestamp"])
     h_list = []
     for h in account.history_reverse(start=start,
                                      stop=stop,
                                      use_block_num=False,
                                      batch_size=10,
                                      raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 9)
     self.assertEqual(h_list[-1][0], 1)
     self.assertEqual(h_list[0][1]['block'],
                      h_all_raw[-10 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-2 + zero_element][1]['block'])
     h_list = []
     for h in account.get_account_history(10,
                                          10,
                                          use_block_num=False,
                                          order=1,
                                          raw_output=True):
         h_list.append(h)
     # self.assertEqual(h_list[0][0], zero_element)
     self.assertEqual(h_list[-1][0], 10)
     self.assertEqual(h_list[0][1]['block'], h_all_raw[-1][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-11 + zero_element][1]['block'])
     h_list = []
     for h in account.get_account_history(10,
                                          10,
                                          use_block_num=False,
                                          start=1,
                                          stop=9,
                                          order=1,
                                          raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 1)
     self.assertEqual(h_list[-1][0], 9)
     self.assertEqual(h_list[0][1]['block'],
                      h_all_raw[-2 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-10 + zero_element][1]['block'])
     start = formatTimeString(h_list[0][1]["timestamp"])
     stop = formatTimeString(h_list[-1][1]["timestamp"])
     h_list = []
     for h in account.get_account_history(10,
                                          10,
                                          use_block_num=False,
                                          start=start,
                                          stop=stop,
                                          order=1,
                                          raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 1)
     self.assertEqual(h_list[-1][0], 9)
     self.assertEqual(h_list[0][1]['block'],
                      h_all_raw[-2 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-10 + zero_element][1]['block'])
     h_list = []
     for h in account.get_account_history(10,
                                          10,
                                          use_block_num=False,
                                          order=-1,
                                          raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 10)
     # self.assertEqual(h_list[-1][0], zero_element)
     self.assertEqual(h_list[0][1]['block'],
                      h_all_raw[-11 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'], h_all_raw[-1][1]['block'])
     h_list = []
     for h in account.get_account_history(10,
                                          10,
                                          use_block_num=False,
                                          start=9,
                                          stop=1,
                                          order=-1,
                                          raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 9)
     self.assertEqual(h_list[-1][0], 1)
     self.assertEqual(h_list[0][1]['block'],
                      h_all_raw[-10 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-2 + zero_element][1]['block'])
     start = formatTimeString(h_list[0][1]["timestamp"])
     stop = formatTimeString(h_list[-1][1]["timestamp"])
     h_list = []
     for h in account.get_account_history(10,
                                          10,
                                          start=start,
                                          stop=stop,
                                          order=-1,
                                          raw_output=True):
         h_list.append(h)
     self.assertEqual(h_list[0][0], 9)
     self.assertEqual(h_list[-1][0], 1)
     self.assertEqual(h_list[0][1]['block'],
                      h_all_raw[-10 + zero_element][1]['block'])
     self.assertEqual(h_list[-1][1]['block'],
                      h_all_raw[-2 + zero_element][1]['block'])
Ejemplo n.º 5
0
 def test_formatTimeString(self):
     t = "2018-07-10T10:08:39"
     t = formatTimeString(t)
     t2 = addTzInfo(datetime(2018, 7, 10, 10, 8, 39))
     self.assertEqual(t, t2)