Example #1
0
 def export_bankuai_stock(self, out_file, in_bk=[]):
     # If in_bk parameter is not assigned, export all the bankuai stocks
     # in_bk could be [行业板块, 浙江板块] or [行业板块] 
     bkst_exception = {}
     out_file = return_new_name_for_existing_file(out_file)
     bkstfile = open(out_file, 'wb') # open in wb is used to remove the blank lines
     bkstfile_writer = csv.writer(bkstfile,quoting=csv.QUOTE_NONNUMERIC)
     bkst_head = [u'板块',u'子版块',u'板块名称',u'股票代码',u'股票名称']
     bkstfile_writer.writerow(bkst_head)
     for sub_bk in self.__bankuai_tree[u'板块']["children"]:
         if len(in_bk)>0 and sub_bk != in_bk[0]: continue
         print_log("Start to process -->" + sub_bk + "...")
         for dtl_bk in self.__bankuai_tree[u'板块']["children"][sub_bk]["children"]:
             if len(in_bk)>1 and dtl_bk != in_bk[1]: continue
             print_log("Start to process -->" + sub_bk + "-->" + dtl_bk + "...")
             parent_bk = []
             for i in self.return_stock_in_bankuai([u'板块', sub_bk, dtl_bk]):
                 bkst = []
                 if not isinstance(i, list):
                     parent_bk.append(i)
                 else:
                     for j in i:
                         bkst = parent_bk + j
                         try:
                             bkstfile_writer.writerow(bkst)
                         except:
                             if not j[0] in bkst_exception: bkst_exception[j[0]] = j[1]
     bkstfile.close()
     if len(bkst_exception.keys())>0: 
         print_log("There are " + str(len(bkst_exception.keys())) + " exceptions!")
         for i in bkst_exception:
             print i + bkst_exception[i]
     else:
         print_log("Completed successfully.")
     return bkst_exception
Example #2
0
 def export_bankuai_status(self, out_file, in_bk=[]):
     # If in_bk parameter is not assigned, export all the bankuais
     # in_bk could be [行业板块]
     bkbk_exception = []
     out_file = return_new_name_for_existing_file(out_file)
     bkbkfile = open(out_file, 'wb') # open in wb is used to remove the blank lines
     bkbkfile_writer = csv.writer(bkbkfile,quoting=csv.QUOTE_NONNUMERIC)
     bkbk_head = [u'板块',u'子版块',u'板块名称',u'涨跌幅',u'总市值(亿)',u'换手率',u'上涨家数',u'下跌家数',u'领涨股票代码',u'领涨股票',u'领涨股票涨跌幅']
     bkbkfile_writer.writerow(bkbk_head)
     for bk in self.__bankuai_tree[u'板块']["children"]:
         if len(in_bk)>0 and bk != in_bk[0]: continue
         print_log("Start to process -->" + bk + "...")
         parent_bk = []
         for i in self.return_bankuai_in_bankuai([u'板块',bk]):
             bkbk = []
             if not isinstance(i, list):
                 parent_bk.append(i)
             else:
                 for j in i:
                     bkbk = parent_bk + j
                     try:
                         bkbkfile_writer.writerow(bkbk)
                     except:
                         if j[0] not in bkbk_exception: bkbk_exception.append(j[0])
     bkbkfile.close()
     if len(bkbk_exception)>0: 
         print_log("There are " + len(bkbk_exception) + " exceptions!")
         for i in bkbk_exception:
             print i
     else:
         print_log("Completed successfully.")
     return bkbk_exception