From 67b0c90f94248a51aac3424d90cac9176afcc906 Mon Sep 17 00:00:00 2001 From: CodeAceKing382 Date: Mon, 8 Jan 2024 22:40:49 +0530 Subject: [PATCH 1/2] Fix casing of Mastermind/mastermind.py --- Mastermind/mastermind.py | 51 ---------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 Mastermind/mastermind.py diff --git a/Mastermind/mastermind.py b/Mastermind/mastermind.py deleted file mode 100644 index fe07173..0000000 --- a/Mastermind/mastermind.py +++ /dev/null @@ -1,51 +0,0 @@ -import random - -num = random.randrange(1000, 10000) - -n = int(input("Guess the 4 digit number:")) - -if n == num: - print("Great! You guessed the number in just 1 try! You're a Mastermind!") -else: - # counts the number of tries made - ctr = 0 - - - while n != num: - - ctr += 1 - count = 0 - - n = str(n) - num = str(num) - - # correct[] list stores digits which are correct - correct = ["X"] * 4 - - for i in range(0, 4): - # here replacing the correctlu guessed digit with "X" - if n[i] == num[i]: - count += 1 - correct[i] = n[i] - else: - continue - - # when not all the digits are guessed correctly. - if (count < 4) and (count != 0): - print("Not quite the number. But you did get ", count, " digit(s) correct!") - print("Also these numbers in your input were correct.") - for k in correct: - print(k, end=" ") - print("\n") - print("\n") - n = int(input("Enter your next choice of numbers: ")) - - # when none of the digits are guessed correctly. - elif count == 0: - print("None of the numbers in your input match.") - n = int(input("Enter your next choice of numbers: ")) - - # condition for equality. - if n == num: - print("You've become a Mastermind!") - print("It took you only", ctr, "tries.") \ No newline at end of file From 1412a75328d7f63f852d4f625f2529a90e85fafb Mon Sep 17 00:00:00 2001 From: CodeAceKing382 Date: Mon, 8 Jan 2024 22:42:39 +0530 Subject: [PATCH 2/2] Added Stock_Trading_News_Alerter folder --- Stock_Trading_News_Alerter/README.txt | 34 +++++++++++ Stock_Trading_News_Alerter/stock alerter.py | 65 +++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 Stock_Trading_News_Alerter/README.txt create mode 100644 Stock_Trading_News_Alerter/stock alerter.py diff --git a/Stock_Trading_News_Alerter/README.txt b/Stock_Trading_News_Alerter/README.txt new file mode 100644 index 0000000..9c25dcd --- /dev/null +++ b/Stock_Trading_News_Alerter/README.txt @@ -0,0 +1,34 @@ +Stock Trading News Alerter + +Description: +A Python-based tool designed to monitor stock prices of any company. +Initially demonstrated with Tesla (TSLA), now adaptable for any stock symbol. +Utilizes APIs from Alpha Vantage and NewsAPI for real-time financial and news data. +Sends SMS alerts for significant stock price changes via the Twilio API. + +Features: +Monitors stock prices of user-specified companies. +Compares daily closing prices to identify significant percentage changes. +Fetches relevant news if stock price change exceeds a certain threshold. +Automated SMS updates for stock price changes and related news. + +Pre-requisites: +Python installation. +Python modules: requests, twilio. +API keys from Alpha Vantage, NewsAPI, and Twilio. +Twilio account with a virtual number and a verified phone number. + +Setup Instructions: +Install required Python modules. +Obtain API keys by signing up for Alpha Vantage, NewsAPI, and Twilio. +Clone the repository. +Input API keys and phone numbers in the script variables. + +Usage: +Execute the script. +Input the desired stock symbol and company name when prompted. +Receive SMS alerts for selected stock's significant price changes and news. + +Enhancements: +Adaptability to monitor any stock symbol as per user input. +Enhanced user interaction with prompts for stock symbol and company name. diff --git a/Stock_Trading_News_Alerter/stock alerter.py b/Stock_Trading_News_Alerter/stock alerter.py new file mode 100644 index 0000000..48da329 --- /dev/null +++ b/Stock_Trading_News_Alerter/stock alerter.py @@ -0,0 +1,65 @@ +import requests +from twilio.rest import Client + +# User inputs for stock and company +STOCK_NAME = input("Enter the stock symbol (e.g., TSLA for Tesla): ").upper() +COMPANY_NAME = input("Enter the full company name (e.g., Tesla Inc): ") + +# Twilio and API configurations +VIRTUAL_TWILIO_NUMBER = "your virtual twilio number" +VERIFIED_NUMBER = "your own phone number verified with Twilio" +STOCK_API_KEY = "YOUR OWN API KEY FROM ALPHAVANTAGE" +NEWS_API_KEY = "YOUR OWN API KEY FROM NEWSAPI" +TWILIO_SID = "YOUR TWILIO ACCOUNT SID" +TWILIO_AUTH_TOKEN = "YOUR TWILIO AUTH TOKEN" + +# API Endpoints +STOCK_ENDPOINT = "https://www.alphavantage.co/query" +NEWS_ENDPOINT = "https://newsapi.org/v2/everything" + +# Get yesterday's closing stock price +stock_params = { + "function": "TIME_SERIES_DAILY", + "symbol": STOCK_NAME, + "apikey": STOCK_API_KEY, +} + +response = requests.get(STOCK_ENDPOINT, params=stock_params) +data = response.json()["Time Series (Daily)"] +data_list = [value for (key, value) in data.items()] +yesterday_data = data_list[0] +yesterday_closing_price = yesterday_data["4. close"] + +# Get the day before yesterday's closing stock price +day_before_yesterday_data = data_list[1] +day_before_yesterday_closing_price = day_before_yesterday_data["4. close"] + +# Calculate the difference in price +difference = float(yesterday_closing_price) - float(day_before_yesterday_closing_price) +up_down = "🔺" if difference > 0 else "🔻" + +# Calculate the percentage difference +diff_percent = round((difference / float(yesterday_closing_price)) * 100) + +# Check for significant change and get news +if abs(diff_percent) > 1: + news_params = { + "apiKey": NEWS_API_KEY, + "qInTitle": COMPANY_NAME, + } + + news_response = requests.get(NEWS_ENDPOINT, params=news_params) + articles = news_response.json()["articles"] + three_articles = articles[:3] + + # Create a formatted list of the first 3 articles + formatted_articles = [f"{STOCK_NAME}: {up_down}{diff_percent}%\nHeadline: {article['title']}. \nBrief: {article['description']}" for article in three_articles] + + # Send each article as a separate message via Twilio + client = Client(TWILIO_SID, TWILIO_AUTH_TOKEN) + for article in formatted_articles: + message = client.messages.create( + body=article, + from_=VIRTUAL_TWILIO_NUMBER, + to=VERIFIED_NUMBER + ) \ No newline at end of file