def getAllHashChallenges(self): pt = PrettyTable() r = requests.get(url=f"{self._url}/challenge/hash", headers=self._appauth.generateGetHeader()) if r.status_code != 200: raise StatusCodeError(str(r.status_code)) (ok, data) = unpack(r.json()) if ok: pt = from_json(json.dumps(data)) return pt
def getAllScoreboard(self): pt = PrettyTable() r = requests.get(url=f"{self._url}/scoreboard", headers=self._appauth.generateGetHeader()) if r.status_code != 200: raise StatusCodeError(str(r.status_code)) (ok, data) = unpack(r.json()) if ok: pt = from_json(json.dumps(data)) else: crt.writeDebug(str(data)) return pt
def testJSONAndBack(self): json_string = self.x.get_json_string() new_table = from_json(json_string) assert new_table.get_string() == self.x.get_string()
def generate_roll_html(roll_rows, trade_times): if roll_rows is None: return '' clean_num = 0 roll_num = 0 create_roll_num = 0 over_rise_num = 0 roll_row_html = """<div class="panel-group" id="accordion">""" sorted_items = sorted(roll_rows.items(), key=lambda item: item[0], reverse=True) for date, rows in sorted_items: d = date.strftime('%Y-%m-%d') collapse_id = d.replace("-", "_") if '高估清仓' in rows[1]['desc']: d += ' [清仓]' clean_num += 1 elif '轮动' in rows[1]['desc']: i = 0 for row in rows: del row['price'] del row['old_price'] del row['premium'] del row['old_premium'] del row['old_amount'] del row['old_percent'] if row['desc'] == '轮动买入' or row['desc'] == '': i += 1 if len(rows) == i: d += ' [建仓]' create_roll_num += 1 else: d += ' [定时调仓]' roll_num += 1 elif '建仓' in rows[1]['desc']: d += ' [建仓]' create_roll_num += 1 else: if '超过' in rows[1]['desc']: d += ' [超涨调仓]' over_rise_num += 1 collapse_name = d rows = sorted(rows, key=lambda x: x['desc']) roll_table = from_json(json.dumps(rows)) roll_table_html = build_table_html(roll_table, table_rows_size=6) roll_row_html += """ <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" data-parent="#accordion" href="#{collapse_id}"> {collapse_name} </a> </h4> </div> <div id="{collapse_id}" class="panel-collapse collapse"> <div class="panel-body"> {collapse_content} </div> </div> </div> """.format(collapse_id=collapse_id, collapse_name=collapse_name, collapse_content=roll_table_html) roll_row_html += "</div>" html = "<br/>调仓记录: (共" + str(trade_times) + "个交易日, 建仓:" + str( create_roll_num) + "次, 定时调仓:" + str(roll_num) + "次, 超涨调仓:" + str( over_rise_num) + "次, 清仓:" + str( clean_num) + "次)<br/>" + roll_row_html return html