Beispiel #1
0
 def complementAll(self):
     end_date = date.today()
     if end_date.weekday() == 0:
         end_date = end_date - timedelta(3)
     codes1 = self.__sh_exchange.getDelisted()
     codes2 = self.__sh_exchange.getHalted()
     codes3 = self.__sz_exchange.getDelisted()
     codes4 = self.__sz_exchange.getHalted()
     for name in os.listdir(self.__stocks_folder):
         last_date = datetime.strptime(name[0:10], '%Y-%m-%d').date()
         code = name[11:17]
         if code in codes1 or code in codes2 or code in codes3 or code in codes4:
             continue
         if end_date > last_date:
             start_date = last_date + timedelta(1)
             content = self.__wy.getDayData(code,
                                            end_date.strftime('%Y%m%d'),
                                            start_date.strftime('%Y%m%d'))
             helper = utils.CSVHelper(content)
             next(helper)
             try:
                 latest_date = next(helper)[0:10]
                 path = self.__stocks_folder + name
                 with open(path, 'a') as f:
                     f.writelines(utils.WYRCSVHelper(content, 62))
                 os.rename(
                     path, self.__stocks_folder + latest_date + '-' +
                     '%s.csv' % code)
             except StopIteration:
                 continue
Beispiel #2
0
 def downloadSingle(self,
                    code,
                    end_date: date = date.today().strftime('%Y%m%d')):
     content = self.__wy.getDayData(code, end_date)
     helper = utils.CSVHelper(content)
     next(helper)
     latest_date = next(helper)[0:10]
     with open(self.__stocks_folder + latest_date + '-' + '%s.csv' % code,
               'w',
               newline='') as f:
         f.write(content[0:62])
         helper = utils.WYRCSVHelper(content, 62)
         f.writelines(helper)
Beispiel #3
0
 def reDownloadAll(self):
     sh_codes, sz_codes = self.__sh_exchange.getAllCodes(
     ), self.__sz_exchange.getAllCodes()
     end_date = date.today().strftime('%Y%m%d')
     for codes in sh_codes, sz_codes:
         for code in codes:
             content = self.__wy.getDayData(code, end_date)
             helper = utils.CSVHelper(content)
             next(helper)
             latest_date = next(helper)[0:10]
             with open(self.__stocks_folder + latest_date + '-' +
                       '%s.csv' % code,
                       'w',
                       newline='') as f:
                 f.write(content[0:62])
                 helper = utils.WYRCSVHelper(content, 62)
                 f.writelines(helper)
Beispiel #4
0
 def complementSome(self, names, end_date):
     for name in names:
         last_date = datetime.strptime(name[0:10], '%Y-%m-%d').date()
         if end_date > last_date:
             code = name[11:17]
             start_date = last_date + timedelta(1)
             content = self.__wy.getDayData(code,
                                            end_date.strftime('%Y%m%d'),
                                            start_date.strftime('%Y%m%d'))
             helper = utils.CSVHelper(content)
             next(helper)
             try:
                 latest_date = next(helper)[0:10]
                 path = self.__stocks_folder + name
                 with open(path, 'a') as f:
                     f.writelines(utils.WYRCSVHelper(content, 62))
                     os.rename(
                         path, self.__stocks_folder + latest_date + '-' +
                         '%s.csv' % code)
             except StopIteration:
                 continue
Beispiel #5
0
 def getHalted(self):
     text = self.__get(self.__base_url.replace('%d', '4'))
     h = utils.CSVHelper(text)
     next(h)
     return [row[0:6] for row in h if not row.startswith('900')]
Beispiel #6
0
 def getCurrentCodes(self):
     text = self.__get(self.__base_url.replace('%d', '1'))
     h = utils.CSVHelper(text)
     next(h)
     return [row[0:6] for row in h]