Skip to content

Commit

Permalink
updated the stock scrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
codeperfectplus committed May 28, 2024
1 parent cae19ae commit feff87d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dash_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
today_date = datetime.datetime.now(IST).strftime('%d-%m-%Y')

app = Dash(__name__)
app.title = 'Stock Alert Dashboard(v1.0)'
app.title = 'Stock Alert Dashboard(v1.1)'

def get_filtered_data():
df = pd.read_csv(os.path.join(root_dir, 'data/stock.csv'), header=None)
Expand Down Expand Up @@ -139,7 +139,7 @@ def get_dash_table(table_id, df):

app.layout = html.Div([

html.H1('Stock Alert Dashboard(v1.0)',
html.H1('Stock Alert Dashboard(v1.1)',
style={'textAlign': 'center', 'color': '#0099ff', 'font-family': 'Courier New',
'font-size': '30px', 'font-weight': 'bold', 'margin-top': '20px'}),
# update dbc badge
Expand Down
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"stock_name": "Vodafone Idea Ltd", "symbol": "IDEA:NSE", "min_price": 8.5, "max_price": 11.5, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Steel Authority of India Limited", "symbol": "SAIL:NSE", "min_price": 77.9, "max_price": 130, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Birlasoft Ltd", "symbol": "BSOFT:NSE", "min_price": 283.0, "max_price": 500, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Trident Ltd", "symbol": "TRIDENT:NSE", "min_price": 36.25, "max_price": 70, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "KPIT Technologies Ltd", "symbol": "KPITTECH:NSE", "min_price": 505.5, "max_price": 700, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Jubilant Ingrevia Ltd", "symbol": "JUBLINGREA:NSE", "min_price": 450.0, "max_price": 700, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Infosys Ltd", "symbol": "INFY:NSE", "min_price": 1459.0, "max_price": 2000, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Tata Power Company Limited", "symbol": "TATAPOWER:NSE", "min_price": 216.3, "max_price": 241.1, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Tata Motors Limited", "symbol": "TATAMOTORS:NSE", "min_price": 396.25, "max_price": 510, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Coforge Ltd", "symbol": "COFORGE:NSE", "min_price": 3754.9, "max_price": 4759, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Bharti Airtel Limited", "symbol": "BHARTIARTL:NSE", "min_price": 686.45, "max_price": 766.5, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Coal India Ltd", "symbol": "COALINDIA:NSE", "min_price": 157.2, "max_price": 236.35, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Hindustan Copper Ltd.", "symbol": "HINDCOPPER:NSE", "min_price": 101.7, "max_price": 150, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Indian Oil Corporation Ltd", "symbol": "IOC:NSE", "min_price": 66.45, "max_price": 140, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Oil & Natural Gas Corporation Limited", "symbol": "ONGC:NSE", "min_price": 127.65, "max_price": 171.35, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Reliance Industries Ltd", "symbol": "RELIANCE:NSE", "min_price": 2293.8, "max_price": 2628.85, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Affle (India) Ltd", "symbol": "AFFLE:NSE", "min_price": 1053.0, "max_price": 1300, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Borosil Renewables Ltd", "symbol": "BORORENEW:NSE", "min_price": 543.8, "max_price": 700, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Gail India", "symbol": "GAIL:NSE", "min_price": 85.2, "max_price": 155.8, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Zomato Ltd", "symbol": "ZOMATO:NSE", "min_price": 58.5, "max_price": 100, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Yes Bank Limited", "symbol": "YESBANK:NSE", "min_price": 13.15, "max_price": 15.75, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Larsen & Toubro Limited", "symbol": "LT:NSE", "min_price": 1610.0, "max_price": 1915.0, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "NTPC Limited", "symbol": "NTPC:NSE", "min_price": 128.95, "max_price": 165.45, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "ITC Ltd", "symbol": "ITC:NSE", "min_price": 214.75, "max_price": 332.1, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Apple Inc", "symbol": "AAPL:NASDAQ", "min_price": 137.59, "max_price": 180, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "Tesla Inc", "symbol": "TSLA:NASDAQ", "min_price": 204.99, "max_price": 900, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "Amazon Inc", "symbol": "AMZN:NASDAQ", "min_price": 106.9, "max_price": 3200, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "Meta Platform(Facebook)", "symbol": "FB2A:ETR", "min_price": 131.4, "max_price": 190, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "Alphabet Inc", "symbol": "GOOGL:NASDAQ", "min_price": 96.56, "max_price": 3000, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "NVIDIA Corporation", "symbol": "NVDA:NASDAQ", "min_price": 112.27, "max_price": 300, "buy": true, "market": "US", "currency": "Dollar"}]
[{"stock_name": "Vodafone Idea Ltd", "symbol": "IDEA:NSE", "min_price": 8.5, "max_price": 15.0, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Steel Authority of India Limited", "symbol": "SAIL:NSE", "min_price": 77.9, "max_price": 166.6, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Birlasoft Ltd", "symbol": "BSOFT:NSE", "min_price": 283, "max_price": 634.5, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Trident Ltd", "symbol": "TRIDENT:NSE", "min_price": 36.25, "max_price": 70, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "KPIT Technologies Ltd", "symbol": "KPITTECH:NSE", "min_price": 505.5, "max_price": 1552.0, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Jubilant Ingrevia Ltd", "symbol": "JUBLINGREA:NSE", "min_price": 450, "max_price": 700, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Infosys Ltd", "symbol": "INFY:NSE", "min_price": 1459, "max_price": 2000, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Tata Power Company Limited", "symbol": "TATAPOWER:NSE", "min_price": 216.3, "max_price": 446.4, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Tata Motors Limited", "symbol": "TATAMOTORS:NSE", "min_price": 396.25, "max_price": 959.2, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Coforge Ltd", "symbol": "COFORGE:NSE", "min_price": 3754.9, "max_price": 5253.9, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Bharti Airtel Limited", "symbol": "BHARTIARTL:NSE", "min_price": 686.45, "max_price": 1380.4, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Coal India Ltd", "symbol": "COALINDIA:NSE", "min_price": 157.2, "max_price": 494.75, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Hindustan Copper Ltd.", "symbol": "HINDCOPPER:NSE", "min_price": 101.7, "max_price": 370.05, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Indian Oil Corporation Ltd", "symbol": "IOC:NSE", "min_price": 66.45, "max_price": 169.05, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Oil & Natural Gas Corporation Limited", "symbol": "ONGC:NSE", "min_price": 127.65, "max_price": 278.3, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Reliance Industries Ltd", "symbol": "RELIANCE:NSE", "min_price": 2293.8, "max_price": 2934.9, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Affle (India) Ltd", "symbol": "AFFLE:NSE", "min_price": 1053, "max_price": 1300, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Borosil Renewables Ltd", "symbol": "BORORENEW:NSE", "min_price": 506.6, "max_price": 700, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Gail India", "symbol": "GAIL:NSE", "min_price": 85.2, "max_price": 202.6, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Zomato Ltd", "symbol": "ZOMATO:NSE", "min_price": 58.5, "max_price": 184.1, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Yes Bank Limited", "symbol": "YESBANK:NSE", "min_price": 13.15, "max_price": 23.0, "buy": true, "market": "IN", "currency": "INR"}, {"stock_name": "Larsen & Toubro Limited", "symbol": "LT:NSE", "min_price": 1610, "max_price": 3647.0, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "NTPC Limited", "symbol": "NTPC:NSE", "min_price": 128.95, "max_price": 370.15, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "ITC Ltd", "symbol": "ITC:NSE", "min_price": 214.75, "max_price": 432.25, "buy": false, "market": "IN", "currency": "INR"}, {"stock_name": "Apple Inc", "symbol": "AAPL:NASDAQ", "min_price": 137.59, "max_price": 189.98, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "Tesla Inc", "symbol": "TSLA:NASDAQ", "min_price": 179.24, "max_price": 900, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "Amazon Inc", "symbol": "AMZN:NASDAQ", "min_price": 106.9, "max_price": 3200, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "Meta Platform(Facebook)", "symbol": "FB2A:ETR", "min_price": 131.4, "max_price": 439.85, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "Alphabet Inc", "symbol": "GOOGL:NASDAQ", "min_price": 96.56, "max_price": 3000, "buy": true, "market": "US", "currency": "Dollar"}, {"stock_name": "NVIDIA Corporation", "symbol": "NVDA:NASDAQ", "min_price": 112.27, "max_price": 1064.69, "buy": true, "market": "US", "currency": "Dollar"}]
35 changes: 28 additions & 7 deletions stock_scrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

IST = pytz.timezone('Asia/Kolkata')

current_time = datetime.datetime.now(IST).strftime('%H:%M:%S')

def check_alert(config):
stock_data = fetch_data(config['symbol'])
Expand Down Expand Up @@ -88,14 +87,36 @@ def main():
check_alert(config)
update_config(configs)


def print_time_left(minutes_left, print_time_delay=1):
seconds_left = minutes_left * 60
while seconds_left > 0:
print("Remaining time: {} mins".format(round(seconds_left / 60, 2)), end='\r')
time.sleep(print_time_delay)
seconds_left -= print_time_delay
minutes_left -= print_time_delay / 60

if __name__ == '__main__':
while True:
if current_time > '08:55:00' and current_time < '15:30:00':
market_open_timing = '09:00:00'
market_close_timing = '15:30:00'
current_time = datetime.datetime.now(IST).strftime('%H:%M:%S')
current_day = datetime.datetime.now(IST).strftime('%A')
if current_day in ['Saturday', 'Sunday']:
print('Market is closed')
print('Market will open on Monday at {}'.format(market_open_timing))
time.sleep(300)
continue

elif current_time < market_open_timing or current_time > market_close_timing:
print('Market is closed')
differnce = datetime.datetime.strptime(market_open_timing, '%H:%M:%S') - datetime.datetime.strptime(current_time, '%H:%M:%S')
differnce = differnce.total_seconds()/60
print('Market will open in {} minutes'.format(differnce))
# start a timer and print in the reverse order
print_time_left(differnce)
continue
else:
check_overall()
main()
time.sleep(20)
else:
print('Market is closed')
# delte csv file
shutil.rmtree('data/stock.csv', ignore_errors=True)
time.sleep(300)

0 comments on commit feff87d

Please sign in to comment.