- Anti-tampering. This automation script can help you test any file and identify whether it has been tampered with.
# Import the hashlib module for encryption hash functions.
import hashlib
# Import the os module for file and directory operations.
import os
# Define the function calculate_sha256 to compute the SHA-256 hash value of a file.
def calculate_sha256(file_path):
sha256 = hashlib.sha256() # Create a sha256 hash object
# Open the file in binary read mode
with open(file_path, 'rb') as file:
# Read the file content, reading 4096 bytes at a time
for chunk in iter(lambda: file.read(4096), b''):
sha256.update(chunk) # Update the state of the hash object
return sha256.hexdigest() # Return the hexadecimal representation of the hash value
# Define the function check_integrity to verify the integrity of a file.
def check_integrity(file_path, expected_checksum):
actual_checksum = calculate_sha256(file_path) # Calculate the actual SHA-256 hash value of the file
return actual_checksum == expected_checksum # Compare the actual hash value with the expected hash value
# If this script is run directly.
if __name__ == "__main__":
file_path = input("Enter the path to the file: ") # Get the file path from user input
expected_checksum = input("Enter the expected SHA-256 checksum: ") # Get the expected SHA-256 hash value from user input
# Check if the file exists
if os.path.isfile(file_path):
# Call the check_integrity function to verify file integrity
if check_integrity(file_path, expected_checksum):
print("File integrity verified: The file has not been tampered with.") # Verification successful
else:
print("File integrity check failed: The file may have been tampered with.") # Verification failed
else:
print("Error: File not found.") # File not found error message
- Intelligent Trading This automation script can help traders and investors gain a good understanding of any stock they want to invest in. It uses Python's Prophet library to predict recent stock prices based on historical stock data obtained from Yahoo Finance.
# Import the Streamlit library to create a web application
import streamlit as st
# Import date for date handling
from datetime import date
# Import the yfinance library to get stock data from Yahoo Finance
import yfinance as yf
# Import the Prophet library for time series forecasting
from prophet import Prophet
# Import the Plotly plotting interface for Prophet and Plotly graph objects
from prophet.plot import plot_plotly
from plotly import graph_objs as go
# Set the start date for predictions and the current date
START = "2015-01-01"
TODAY = date.today().strftime("%Y-%m-%d")
# Create the application title using Streamlit
st.title('Stock Forecast App')
# Set a selection box for users to choose stocks
stocks = ('MSFT', "TSLA", 'GOOG', 'AAPL', "NVDA")
selected_stock = st.selectbox('Select dataset for prediction', stocks)
# Create a slider for users to select the number of years for prediction, ranging from 1 to 4 years
n_years = st.slider('Years of prediction:', 1, 4)
period = n_years * 365 # Convert years to days
# Define a caching function to load stock data, avoiding reloading on every session
@st.cache
def load_data(ticker):
data = yf.download(ticker, START, TODAY) # Download stock data from Yahoo Finance
data.reset_index(inplace=True) # Reset the DataFrame index
return data
# Display the data loading status
data_load_state = st.text('Loading data...')
data = load_data(selected_stock) # Call the function to load data
data_load_state.text('Loading data... done!') # Update loading status
# Display the last few rows of the raw data
st.subheader('Raw data')
st.write(data.tail())
# Define a function to plot the opening and closing prices of the raw data
def plot_raw_data():
fig = go.Figure()
fig.add_trace(go.Scatter(x=data['Date'], y=data['Open'], name="stock_open"))
fig.add_trace(go.Scatter(x=data['Date'], y=data['Close'], name="stock_close"))
fig.layout.update(title_text='Time Series data with Rangeslider', xaxis_rangeslider_visible=True)
st.plotly_chart(fig)
plot_raw_data()
# Use Prophet for forecasting
df_train = data[['Date', 'Close']]
df_train = df_train.rename(columns={"Date": "ds", "Close": "y"})
m = Prophet()
m.fit(df_train)
future = m.make_future_dataframe(periods=period)
forecast = m.predict(future)
# Display and plot the forecast data
st.subheader('Forecast data')
st.write(forecast.tail())
st.write(f'Forecast plot for {n_years} years')
fig1 = plot_plotly(m, forecast)
st.plotly_chart(fig1)
# Display forecast components
st.write("Forecast components")
fig2 = m.plot_components(forecast)
st.write(fig2)