def handle(self, start, end, *args, **options): print "__xyf trade history" if not token: print "no token!!" return if not start or not end: end_date = datetime.now() start_date = end_date - timedelta(3) start = utils.datetime_to_string(start_date, format_str="%Y%m%d") end = utils.datetime_to_string(end_date, format_str="%Y%m%d") cookies = get_cookies(token) print start, end data = get_data(start, end, cookies) write_to_db(data)
def handle(self, start, end, *args, **options): print "__jk terminal" if not token: print "no token!!" return date_list = [] if not start or not end: end_date = datetime.now() for i in range(3): adate = end_date - timedelta(i) date_list.append(adate) else: start_date = utils.string_to_datetime(start) end_date = utils.string_to_datetime(end) date_list.append(start_date) n = 1 while True: day_date = start_date + timedelta(n) date_list.append(day_date) n += 1 if day_date >= end_date: break cookies = get_cookies(token) for adate in date_list: adate_str = utils.datetime_to_string(adate, format_str="%Y-%m-%d") terminal_data = get_trade_data(cookies, adate_str) write_to_db_trade(terminal_data) print "ok"
def handle(self, start, end, table, *args, **options): is_none = False if start is None or end is None: is_none = True end_date = datetime.now() if table == "terminal_update": end_date = end_date - timedelta(3) start_date = end_date - timedelta(30) else: start_date = end_date - timedelta(3) start = utils.datetime_to_string(start_date, format_str="%Y-%m-%d") end = utils.datetime_to_string(end_date, format_str="%Y-%m-%d") print "__sync slkl", start, end, table print datetime.now() if not URL: print "token:", URL return cookies = get_cookies() start1 = "".join(start.split("-")) end1 = "".join(end.split("-")) # D0 if table in ("d0", "all"): d0_data = get_d0_data(cookies, start1, end1) write_to_db_d0(d0_data) # D1 if table in ("d1", "all"): start_date = utils.string_to_datetime(start1) end_date = utils.string_to_datetime(end1) diff = end_date - start_date if is_none: s = -3 else: s = 0 for i in range(s, diff.days + 1)[::-1]: adate = start_date + timedelta(i) adate_str = utils.datetime_to_string(adate) d1_data = get_d1_data(cookies, adate_str) write_to_db_d1(d1_data) # 终端 if table in ("terminal", "terminal_update", "all"): terminal_data = get_terminal_data(cookies, start, end) write_to_db_terminal(terminal_data)
def get_trade_today(start, end, cookies, page): url = "http://sddl.postar.cn/transaction_postxnjnl_his_query.trans" now = datetime.now() now_str = utils.datetime_to_string(now, format_str="%Y%m%d") data = { "BEGINHSTDAT": start, "ENDHSTDAT": now_str, "STLDTSTR": start, "STLDTEND": end, "OPERATING": "stlw/query_txnjnl_agent.jsp", "pageNum": "%s" % page, "numPerPage": "12", "showFlag": "", "XYHeight": "", "FLAG": "2", "SUMTOAL": "", "STLDT_1": "", "TOLCNT": "0", "AGTORG_1": "", "BRANAM_1": "", "MERCID": "", "TERMID": "", "AGENTID": "", "ROTFLG": "", "LOGNO_1": "", "merstlmod": "", "consumetyp": "", "MERNAM_1": "", "BEGINHSTDAT": "", "ENDHSTDAT": "", "TXNCD_1": "", "TXNSTS_1": "", "BRANAM": "", "TXNAMTSTR": "", "TXNAMTEND": "", "OPERSTATUS": "", "POStype": "", "SECPAYFLG": "", "PAYSTATUS": "", "COMFIRFLG": "", "ICCRDFLG": "", } r = requests.post(url, data=data, cookies=cookies) html = r.content.decode("utf-8") soup = BeautifulSoup(html) data = [] total = r1(ur"共\[(\d+)\]条", html) print "total", total, "page", page if not total or not total.isdigit(): disable_token(token) else: total = int(total) content = soup.find("div", class_="pageContent") tbody = content.find("tbody") if tbody: for line in tbody.find_all("tr"): tmp = [] for td in line.find_all("td"): tmp.append(td.text.strip()) data.append(tmp) return data, total