Skip to main content

Posts

Capture Network Traffic in Python

  Below is the code to capture a network traffic in python import requests def check_web_traffic (url): try : response = requests.get(url) if response.status_code == 200 : print ( f"Web traffic for { url } is good." ) else : print ( f"Web traffic for { url } is not as expected. Status code: { response.status_code } " ) except requests.RequestException as e: print ( f"An error occurred: { e } " ) if __name__ == "__main__" : url = 'Put website url here' check_web_traffic(url)

Create Progress bar in Python

Following is the code to create a  Progress bar in Python. For that you need to install  tqdm package Here is the code: from tqdm import tqdm from time import sleep pbar = tqdm( total = 100 ) for i in range ( 10 ): sleep( 0.2 ) pbar.update( 10 ) pbar.close()

NSE Stock Fundamental Analysis in Python

 NSE Stock Fundamental Analysis in Python with yfinance library. Here is the full code: import random import time from tqdm import tqdm import yfinance as yf import pandas as pd from datetime import datetime, timedelta def get_nifty50_symbols():     nifty50_symbols = ["ACC", "PRSMJOHNSN", "AETHER"]     return [symbol + ".NS" for symbol in nifty50_symbols] def get_all_indian_stocks():     # Fetch list of Indian Stocks     url = f".\\Nifty_Stocks_Anaysis.csv"     df = pd.read_csv(url)     symbols = df['SYMBOL'].tolist()     return [symbol + ".NS" for symbol in symbols] def get_stock_data(symbol):     stock = yf.Ticker(symbol)     # Get price data     end_date = datetime.now()     start_date = end_date - timedelta(days=365)     price_data = stock.history(start=start_date, end=end_date)     if price_data.empty:         return None   ...

MySQL connection in JAVA

 Below is the code for MySQL connection in JAVA import java.sql.Connection; import java.sql.DriverManager; public class TestMySql { public static Connection con = null; public static void main(String[] args) { try{   String host = "";         String uName = "";         String uPass= "";        Class.forName("com.mysql.cj.jdbc.Driver");   con = DriverManager.getConnection(host, uName, uPass); System.out.println("Connection Successful..."); con.close();   } catch(Exception e) {  System.out.println(e);}   } }

File Comparison in JAVA

Below is the code for File Comparison in JAVA:  import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException;   public class CompareTextFiles {     public static void main(String[] args) throws IOException     {         BufferedReader reader1 = new BufferedReader(new FileReader("C:\\FileCompare\\File1.txt"));                   BufferedReader reader2 = new BufferedReader(new FileReader("C:\\FileCompare\\File2.txt"));                   String line1 = reader1.readLine();                   String line2 = reader2.readLine();                   boolean areEqual = true;                   int lineNum = 1;                   while (line1 != null || li...

Multiple files creation logic in JAVA

  import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Multiple_Files_Creation_logic { public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub int totalCount = 1001; //userinput String filePath = "C:\\Users\\vmalge\\Desktop\\Test"; String fileName= "V_SHPT_OFR_MDCTEST4_"; String fileType = "csv"; File input = new File(filePath+fileName+"."+fileType);                   for(int counter = 1; counter < totalCount; counter++){     //int size = 250;     //tbd     File myFile = new File("C:\\Test\\result"+fileName+counter+"."+fileType);                                try { ...

Email monitoring in JAVA

 Email monitoring in JAVA. Here is the code: import java.util.Properties; import javax.activation.DataHandler; import javax.activation.DataSource; import javax.activation.FileDataSource; import javax.mail.Authenticator; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; public class MonitoringMail { //public static void sendMail(String mailServer, String from,String username, String password,String port, String[] to, String subject, String messageBody, String attachmentPath, String attachmentName) throws MessagingException, AddressException public void sendMail(String mailServer, String from, String[] to, String subject, String mess...