Skip to content

Instantly share code, notes, and snippets.

@nibrahim
Created May 26, 2018 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibrahim/fd22ad6d036287e131f702317fd13f89 to your computer and use it in GitHub Desktop.
Save nibrahim/fd22ad6d036287e131f702317fd13f89 to your computer and use it in GitHub Desktop.
Get Indian MF prices
import subprocess
import datetime
import urllib.request
def interesting_commodity(commodities, line):
"""Returns True if the given line has one of the given commodities"""
for c in commodities:
if c in line:
return True
return False
def main():
with open("rates.journal", "a") as rates:
data = urllib.request.urlopen("https://www.amfiindia.com/spages/NAVAll.txt")
commodities = set(x.strip() for x in open("./hledger-commodities"))
for idx,i in enumerate(data):
if idx == 40:
break
i = i.decode('utf-8')
if interesting_commodity(commodities, i):
fields = [x.strip() for x in i.split(';')]
scheme_code, div_payout, div_reinvestment, scheme, net_value, repurchase, sale, date = fields
date = datetime.datetime.strptime("25-May-2018", "%d-%b-%Y")
rates.write('"{}" ₹{}\n'.format(div_reinvestment, repurchase))
rates.write("P {} {} {}\n".format(scheme, div_payout, div_reinvestment))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment