Пример #1
0
 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
 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")