コード例 #1
0
import sys
from bsedata.bse import BSE
import pandas as pd
import pprint

b = BSE()
b.updateScripCodes()

#store the scripts codes in BseScripCodes.txt
print(b.getScripCodes(), file=open('BseScripCodes.txt', 'wt'))

#convert scripts codes from BseScripCodes.txt to BseScripCodes.xlsx
df = pd.DataFrame(data=b.getScripCodes(), index=[0])
df = (df.T)
df.to_excel('BseScripCodes.xlsx')
コード例 #2
0
def handle_data():
    comp = request.form['tags']
    print(comp)
    b = BSE()
    b.updateScripCodes()
    d = b.getScripCodes()
    rev_d = dict(map(reversed, d.items()))
    scripcode = rev_d[comp]
    print(scripcode)
    quote = b.getQuote(scripcode)
    company = quote["securityID"]
    print(company)

    # -----------READING NSE DATA
    url = 'https://www.nseindia.com/api/chart-databyindex?index=' + company + 'EQN'
    headers = {
        'referer':
        'https://www.nseindia.com/get-quotes/equity?symbol=' + company,
        'Content-Type': 'application/json; charset=utf-8',
        'user-agent':
        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36',
        'x-requested-with': 'XMLHttpRequest'
    }

    nse = requests.get(url, headers=headers)
    nse_text = nse.text

    nsedata = json.loads(nse_text)
    #print(type(nsedata["grapthData"]))

    l = nsedata["grapthData"]

    #-------------- READ NSE DATA , NOW BSE DATA

    bse_url = 'https://api.bseindia.com/BseIndiaAPI/api/StockReachGraph/w?scripcode=' + str(
        scripcode) + '&flag=0&fromdate=&todate=&seriesid='
    bse = requests.get(bse_url)
    bse_text = bse.text

    bse_data = json.loads(bse_text)
    #print(type(bsedata))

    #------------ READ BSE DATA

    dat = bse_data["Data"]
    dat_dict = json.loads(dat)

    bse_final_list = []
    bse_temp_list = []
    for i in dat_dict:
        #print(i['dttm'])
        date_obj = datetime.strptime(i['dttm'], '%a %b %d %Y %H:%M:%S')
        ms = date_obj.timestamp() * 1000
        ms = int(ms) + 19800000
        bse_temp_list.append(ms)
        bse_temp_list.append(i['dttm'])
        bse_temp_list.append(float(i['vale1']))
        bse_final_list.append(bse_temp_list)
        bse_temp_list = []
    '''
	print("------------------------------------")
	print(len(bse_final_list))
	print(len(l))
	'''
    pprint(l)
    print("-------------------------")
    pprint(bse_final_list)

    labels = []
    values = []
    diff_final_list = []
    diff_temp_list = []
    for j in bse_final_list:
        for k in l:
            if j[0] == k[0]:

                ts = int(j[0]) / 1000
                print(
                    datetime.utcfromtimestamp(ts).strftime(
                        '%Y-%m-%d %H:%M:%S'))

                diff_temp_list.append(j[0])
                diff = abs(float(j[2]) - float(k[1]))

                labels.append(j[0])
                values.append(round(diff, 2))

                diff_temp_list.append(round(diff, 2))
                diff_final_list.append(diff_temp_list)
                diff_temp_list = []
    pprint(diff_final_list)
    print(labels)
    print(values)

    return render_template('graph.html',
                           labels=labels,
                           values=values,
                           name=comp,
                           scode=scripcode,
                           ccode=company)
コード例 #3
0
from bsedata.bse import BSE
import json
b = BSE()
print(b)

b = BSE(update_codes=True)

while True:
    main_input = int(
        input(
            "\nWhat You Want To Do\nPress 1 to Get The List Of Todays Top Gainers\nPress 2 to Get The List Of Todays Top Losers\nPress 3 to Get The List of the Scrip Code Of The Respective Companies\nPress 4 to Get the Information About The Company Stock by Providing the Scrip Code: "
        ))
    scrip_code = b.getScripCodes()
    Gainers = b.topGainers()
    Losers = b.topLosers()
    if main_input == 1:
        print(json.dumps(Gainers, sort_keys=True, indent=4))
    if main_input == 2:
        print(json.dumps(Losers, sort_keys=True, indent=4))
    if main_input == 3:
        print(json.dumps(scrip_code, sort_keys=True, indent=4))
    if main_input == 4:
        Quote = b.getQuote(
            input(
                "Please Enter The Scrip Code To Get The Information About The Company Stock: "
            ))
        print(json.dumps(Quote, sort_keys=True, indent=4))

    con = int(
        input("\nDo You Want to Continue\nPress 1 For Yes\nPress 2 For No: "))
コード例 #4
0
from bsedata.bse import BSE

b = BSE()

data = b.getScripCodes()
# print(data)

# value = b.getQuote("507685")
# # print(value)

# data1 = b.getQuote("532540")
# print(data1)

tg = b.topGainers()
# print(tg)

tl = b.topLosers()
# print(tl)

test = b.verifyScripCode("5325402")
print(test)