示例#1
0
文件: nse.py 项目: jsandy001/nseutils
 def get_bhavcopy_filename(self, d):
     d = mkdate(d)
     day_of_month = d.strftime("%d")
     mon = d.strftime("%b").upper()
     year = d.year
     filename = self.bhavcopy_base_filename % (day_of_month, mon, year)
     return filename
示例#2
0
文件: nse.py 项目: jsandy001/nseutils
 def get_bhavcopy_url(self, d):
     """take date and return bhavcopy url"""
     d = mkdate(d)
     day_of_month = d.strftime("%d")
     mon = d.strftime("%b").upper()
     year = d.year
     url = self.bhavcopy_base_url % (year, mon, day_of_month, mon, year)
     return url
示例#3
0
 def download_one(self, d):
     """download bhavcopy for the given date"""
     # this will keep this method usable for any arbitrary date.
     d = mkdate(d)
     # ex_url = "https://www.nseindia.com/content/historical/EQUITIES/2011/NOV/cm08NOV2011bhav.csv.zip"
     url = self.get_bhavcopy_url(d)
     print(url)
     filename = self.get_bhavcopy_filename(d)
     # response = requests.get(url, headers=self.headers)
     response = self.nse.opener.open(Request(url, None, self.nse.headers))
     zip_file_handle = io.BytesIO(response.read())
     zf = zipfile.ZipFile(zip_file_handle)
     return zf.read(filename).decode("utf-8")