Skip to main content

Posts

Download historical data for all NSE Stocks in Python

Using Python we can download historical data for all NSE stocks for Indian Stock Market. Below are the steps. 1. First download the csv file containing all NSE stock codes. Go to : https://www.nseindia.com/market-data/securities-available-for-trading and click on  Securities available for Equity segment (.csv) to download the file. We use this file to read stock codes to read historical data for them. 2. Install the yfinance package using following command pip install yfinance  3. Below is the code to read all NSE stock historical data: import yfinance as yf import pandas as pd import os NSE_all_stock_codes = pd.read_csv(f'./NSE_Stock_Codes/EQUITY_ALL.csv') print(NSE_all_stock_codes.SYMBOL) for file in os.scandir(f'Historical_Data_All/'):     if file.name.endswith(".csv"):         os.unlink(file.path) for nse_symbol in NSE_all_stock_codes.SYMBOL:     try:         nse_symbol_data = yf.download(f'{nse_symbol}.NS', perio...

How to read a config file in python

 Below is an example which shows how to read a config file in python. Below is the sample config file. Just copy paste the text and save the file as config.ini [basic info] testsiteurl=https://www.google.com/ [locators] #page locators Logo_XPATH=//img[@class='logo'] Searchbar_XPATH=//*[@id='testbox'] Now its time to read the data from above config file. Below is the python code to read the data which is present in above config file. Save the file as configReader.py from configparser import ConfigParser def readConfig(section, key):     config = ConfigParser()     config.read("..\\conf.ini")     return config.get(section, key) print(readConfig("locators","Logo_XPATH"))

Sample file to install dependencies in python

Below is the sample dependencies list file to install for pyhon project. Just do copy paste and save the file as requirement.txt: allure-pytest==2.13.2 allure-python-commons==2.13.2 apipkg==1.5 astor==0.8.1 atomicwrites==1.4.0 attrs==20.3.0 certifi==2021.10.8 chardet==4.0.0 colorama==0.4.4 configparser==5.0.2 crayons==0.4.0 execnet==1.8.0 idna==2.10 iniconfig==1.1.1 packaging==20.9 pluggy==0.13.1 py==1.10.0 pyparsing==2.4.7 pytest==7.4.3 pytest-ast-transformer==1.0.3 pytest-forked==1.3.0 pytest-html==4.1.1 pytest-metadata==3.0.0 pytest-soft-assertions==0.1.2 pytest-xdist==2.2.1 requests==2.25.1 selenium==4.16.0 six==1.15.0 texttable==1.6.3 toml==0.10.2 urllib3==1.26.4 webdriver-manager==4.0.1 openpyxl==3.1.2 coloredlogs==15.0.1 Unidecode == 1.3.7 beautifulsoup4 == 4.12.2 selenium-wire == 5.1.0 In order to install all above dependencies, you need to navigate to the path where the requirement.txt file is located. After locating the path you need to simpliy execute following commmnd to in...

Get WIFI password using python

Below is the code which will help to get you or hack a wifi password. After running the program you will get all nearby available wifi passords in one go.  Here is the code:  # now we will store the profiles data in "data" variable by # running the 1st cmd command using subprocess.check_output data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n') # now we will store the profile by converting them to list profiles = [i.split(":")[1][1:-1] for i in data if "All User Profile" in i] # using for loop in python we are checking and printing the wifi # passwords if they are available using the 2nd cmd command for i in profiles:     # running the 2nd cmd command to check passwords     results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i,                         'key=clear']).decode('utf-8').split('\n...

Change an extension to file in python

Program to change an extension of a file in python: import os import shutil def renamefiles():     filelist = os.listdir(r"source path here")     print(filelist)     os.chdir(r"source path here")     path = os.getcwd()     for filename in filelist:         if filename.endswith(".xml"):             print("Old Name - " + filename)             (prefix, sep, sffix) = filename.rpartition(".")             newfile = filename + '.ok'             if not filename.endswith(".ok"):                 os.rename(filename, newfile)                 print("New Name - " + newfile)                 os.chdir(path) # path to source directory src_dir = r'source path here' # path to destination directory...

Java Program to print Star patterns

 Java Star Pattern Programs: ================================================================= Patterns 1:  package javaPrograms; public class StarPattern { public static void main(String[] args) { //i for rows and j for columns       //row denotes the number of rows you want to print   int i, j, row=6;    //outer loop for rows   for(i=0; i<row; i++)    {    //inner loop for columns   for(j=0; j<=i; j++)    {    //prints stars    System.out.print("* ");    }    //throws the cursor in a new line after printing each line   System.out.println();    }      } } ================================================================= Pattern 2:  package javaPrograms; public class StarPattern1 { public static void main(String[] args) { for(int i=1;i<=4;i++) { ...

Java Program to check if Number is Armstrong or not

 Logic for  Armstrong   number :)  Armstrong Number An  Armstrong  number is a positive m-digit number that is equal to the sum of the m th  powers of their digits. It is also known as  pluperfect , or  Plus Perfect , or  Narcissistic  number. It is an OEIS sequence  A005188 . Let’s understand it through an example. Armstrong Number Example 1:  1 1  =  1 2:  2 1  =  2 3:  3 1  =  3 153:  1 3  + 5 3  + 3 3  = 1 + 125+ 27 =  153 125:  1 3  + 2 3  + 5 3  = 1 + 8 + 125 =  134 (Not an Armstrong Number) 1634:  1 4  + 6 4  + 3 4  + 4 4  = 1 + 1296 + 81 + 256 =  1643 //Armstrong number list:0,1,153,370,371,407,1634 //Eg 153 rest to 3(Total number of digit ) each digit if addition come original number. package javaPrograms; import java.util.Scanner; public class ArmstrongNumber { public static vo...