import requests
import re
orders = pd.read_csv(ORDER_FILENAME, parse_dates=['TIMESTAMP'],
usecols=range(13))
symbols = pd.read_excel('universe.xlsx', sheet_name=UNIVERSE, header=None).values.ravel()
df = orders[orders['SYMBOL'].isin(symbols)]
df = df[df['SERIES'] == "EQ"].reset_index(drop=True)
df['RET'] = (df['CLOSE']/df['PREVCLOSE']) - 1
result = df.sort_values(by='RET', ascending = False).iloc[:NUM_STOCKS]
df = orders[orders['SYMBOL'].isin(symbols)]
result['OPENPRICE'] = 0
s=[]
for symbol in result['SYMBOL']:
url = 'https://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol='+symbol
header = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64)AppleWebKit/537.11 (KHTML, like Gecko)Chrome/23.0.1271.64 Safari/537.11','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3','Accept-Encoding': 'none','Accept-Language': 'en-US,en;q=0.8','Connection': 'keep-alive'}
fetch = requests.get(url, headers=header)
pp='"open":"(.+?)"'
price=re.findall(pp,fetch.text)
price
s.append(price)
newop = pd.Series((num[0] for num in s))
result=result.reset_index(drop=True)
result['OPENPRICE']=newop
result[['TIMESTAMP', 'SYMBOL', 'OPENPRICE']].to_excel('output.xlsx', index=False)
print('Update OPENPRICE in the output.xlsx file')
result[['TIMESTAMP', 'SYMBOL', 'OPENPRICE']]