def delete(): book_id = base.base_id try: book_id = int(argv[1]) except Exception as e: print(argv[1], 'is not an integer.') return if book_id <= base.base_id: print(argv[1], 'is not an illegal id.') return status = base.read() if book_id - base.base_id > len(status): print('Book id', book_id, 'not exist.') return deleted_book = status.pop(book_id - base.base_id - 1) try: affirmative = input( "Delete item:\n %s %s/%s\nSure? (Y/else) " % (deleted_book['book_name'], deleted_book['current_page'], deleted_book['book_page'])) except KeyboardInterrupt: print('\nCanceled.') return if affirmative == 'Y': base.write(status) print('Deleted.') else: print('Canceled.')
def make_market_data(self, current_page): keys = ['hqzqdm', 'hqzqjc', 'hqzrsp', 'hqjrkp', 'hqzjcj', 'hqcjsl', 'hqcjje', 'hqbjw1', 'hqsjw1', 'hqzdf'] url = self.__market_making_url % current_page data = AgreementWay.unpickle(url, 'content') for _item in data: item_list = AgreementWay.format([_item[k] for k in keys]) write(self.__market_making_fn, item_list)
def make_market_data(self, current_page): keys = [ 'hqzqdm', 'hqzqjc', 'hqzrsp', 'hqjrkp', 'hqzjcj', 'hqcjsl', 'hqcjje', 'hqbjw1', 'hqsjw1', 'hqzdf' ] url = self.__market_making_url % current_page data = AgreementWay.unpickle(url, 'content') for _item in data: item_list = AgreementWay.format([_item[k] for k in keys]) write(self.__market_making_fn, item_list)
def agreement(self, current_page): keys = ['hqzqdm', 'hqzqjc', 'hqzrsp', 'hqjrkp', 'hqzjcj', 'hqcjsl', 'hqcjje', 'hqbjw1', 'hqsjw1', 'hqzdf'] url = self.__hq_url % current_page hq_data = self.unpickle(url, 'content') for _item in hq_data: code = _item['hqzqdm'] items_list = self.format([_item[k] for k in keys]) write(self.__fn_hq, items_list) self.agreement_deal(code) self.agreement_declare(code)
def agreement_deal(self, code): start_page, total_pages = 0, 1 keys = ['HQCJJG', 'HQCJSL', 'HQCJJE', 'HQBJYDY', 'HQSJYDY', 'HQCJSJ'] while start_page < total_pages: if start_page == 0: data, total_pages = self.unpickle(self.__deal_url % (start_page, code), 'content', 'totalPages') else: data = self.unpickle(self.__deal_url % (start_page, code), 'content') for _item in data: items_list = [code] items_list.extend([_item[_k] for _k in keys]) write(self.__fn_deal, self.format(items_list)) start_page += 1
def add(): status = base.read() page_number = 0 try: page_number = int(argv[2]) except Exception as e: print(argv[2], 'is not an integer.') return if page_number <= 0: print(argv[2], 'is not an positive integer.') return book_name = argv[1].replace('\t', ' ') page_number_str = str(page_number) status.append({'book_name': book_name, 'book_page': page_number_str, 'current_page': '0'}) base.write(status) print("Book <%s> (%s) added." % (book_name, page_number_str))
def agreement_declare(self, code): buy_start_page, buy_total_pages = 0, 1 sale_start_page, sale_total_pages = 0, 1 info_keys = ['XYWTJG', 'XYWTSL', 'XYYWLB', 'XYJYDY', 'XYYDH', 'XYWTSJ'] while buy_start_page < buy_total_pages: buy_url = self.__declare_buy_url % (buy_start_page, code) if buy_start_page == 0: buy_data, buy_total_pages = self.unpickle(buy_url, 'content', 'totalPages') else: buy_data = self.unpickle(buy_url, 'content') for _item in buy_data: items_list = [code] for _key in info_keys: if 'XYYWLB' == _key: items_list.append(u'定价买入') else: items_list.append(_item[_key]) write(self.__fn_declare, self.format(items_list)) buy_start_page += 1 while sale_start_page < sale_total_pages: sale_url = self.__declare_sale_url % (sale_start_page, code) if sale_start_page == 0: sale_data, sale_total_pages = self.unpickle(sale_url, 'content', 'totalPages') else: sale_data = self.unpickle(sale_url, 'content') for _sale_item in sale_data: items_list = [code] for _key in info_keys: if 'XYYWLB' == _key: items_list.append(u'定价卖出') else: items_list.append(_sale_item[_key]) write(self.__fn_declare, self.format(items_list)) sale_start_page += 1
def read(): book_id = base.base_id current_page = 0 try: book_id = int(argv[1]) except Exception as e: print(argv[1], 'is not an integer.') return if book_id <= base.base_id: print(argv[1], 'is not an illegal id.') return try: current_page = int(argv[2]) except Exception as e: print(argv[2], 'is not an integer.') return if current_page <= 0: print(argv[2], 'is not an positive integer.') return status = base.read() if book_id - base.base_id > len(status): print('Book id', book_id, 'not exist.') return book_status = status[book_id - base.base_id - 1] book_page_str = book_status['book_page'] if int(book_page_str) < current_page: print('Incorrect page.') return current_page_str = str(current_page) origin_page_str = book_status['current_page'] book_status['current_page'] = current_page_str book_name = book_status['book_name'] base.write(status) print("Updated: %s %s/%s->%s/%s" % (book_name, origin_page_str, book_page_str, current_page_str, book_page_str))
def __init__(self): self.__market_making_fn = configs.mm_fn self.__market_making_url = configs.mm_url self.__market_making_headers = configs.mm_headers write(self.__market_making_fn, self.__market_making_headers)
async def show(category: str, region: str): id = base.write(category, region) return {'id': id}
def init(self): write(self.__fn_hq, self.__base_headers) write(self.__fn_deal, self.__deal_headers) write(self.__fn_declare, self.__declare_headers)