Skip to content

Commit 7344e2d

Browse files
committed
2 parents 862574d + c20d256 commit 7344e2d

File tree

17 files changed

+695
-5
lines changed

17 files changed

+695
-5
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

Automate-Emails-Daily/main.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import smtplib
2+
import ssl
3+
import os
4+
from email.message import EmailMessage
5+
from email.utils import formataddr
6+
7+
def send_email(sender_email: str,
8+
sender_name: str,
9+
password:str,
10+
receiver_emails: str ,
11+
email_body: str,
12+
email_subject: str="No subject",)-> None:
13+
14+
msg = EmailMessage()
15+
msg["Subject"] = email_subject
16+
msg["From"] = formataddr((f"{sender_name}", f"{sender_email}"))
17+
msg["BCC"] = sender_email
18+
msg.set_content(email_body)
19+
20+
smtp_port = 587
21+
smtp_server = "smtp.gmail.com"
22+
23+
# Adding ssl layer of security
24+
ssl_context = ssl.create_default_context()
25+
26+
try:
27+
# Creating smtp server
28+
print("Connecting to Server...")
29+
my_server = smtplib.SMTP(smtp_server, smtp_port)
30+
my_server.starttls(context=ssl_context)
31+
32+
# Login to smtp server
33+
my_server.login(sender_email, password)
34+
print("Connected to server!")
35+
36+
# Sending email
37+
print(f"Sending email from: {sender_email}")
38+
print("**************************************")
39+
for receiver in receiver_emails:
40+
msg["To"] = receiver
41+
print(f"Sending email to: {receiver}")
42+
my_server.sendmail(sender_email, receiver, msg.as_string())
43+
print(f"...\nSuccessfully sent to: {receiver}")
44+
print("**************************************")
45+
del msg["To"]
46+
except Exception as e:
47+
print(f"ERROR: {e}")
48+
finally:
49+
my_server.quit()
50+
51+
# change these variables to suite your requirements
52+
sender_email = "[email protected]"
53+
sender_name = "your name"
54+
password = os.environ.get("EMAIL_PASSWORD")
55+
56+
email_subject = "good morning"
57+
email_body = "good morning, hope you have a wonderful day"
58+
59+
60+
61+
send_email(sender_email, sender_name, password, receiver_emails, email_body,email_subject)

HarvestPredictor/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Flask==2.2.5
2-
numpy==1.20.3
2+
numpy==1.22.0
33

44
gunicorn==20.0.4
55
Werkzeug==2.2.3

Profanity Checker/ProfanityChecker.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import speech_recognition as sr
2+
import requests
3+
import nltk
4+
import csv
5+
from nltk.tokenize import word_tokenize
6+
from nltk.corpus import stopwords
7+
from nltk.stem import WordNetLemmatizer
8+
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
9+
import tkinter as tk
10+
from tkinter import filedialog
11+
12+
nltk.download('wordnet')
13+
14+
nltk.download('punkt')
15+
nltk.download('stopwords')
16+
17+
# Initialize the recognizer
18+
r = sr.Recognizer()
19+
20+
# Ask the user whether to record from the microphone or select a file
21+
root = tk.Tk()
22+
root.withdraw()
23+
mode = input("Enter 'mic' to record from microphone or 'file' to select a file: ")
24+
25+
if mode == 'mic':
26+
# Record audio from the user
27+
with sr.Microphone() as source:
28+
print("Say something!")
29+
audio = r.listen(source)
30+
31+
# Use Google Speech Recognition to convert audio to text
32+
try:
33+
text = r.recognize_google(audio)
34+
print("You said: " + text)
35+
36+
except sr.UnknownValueError:
37+
print("Google Speech Recognition could not understand audio")
38+
except sr.RequestError as e:
39+
print("Could not request results from Google Speech Recognition service; {0}".format(e))
40+
41+
elif mode == 'file':
42+
# Select a file using a dialog box
43+
file_path = filedialog.askopenfilename()
44+
print("Selected file:", file_path)
45+
46+
# Convert audio file to audio data
47+
with sr.AudioFile(file_path) as source:
48+
audio = r.record(source)
49+
50+
# Use Google Speech Recognition to convert audio to text
51+
try:
52+
text = r.recognize_google(audio)
53+
print("Transcription: " + text)
54+
55+
56+
except sr.UnknownValueError:
57+
print("Google Speech Recognition could not understand audio")
58+
except sr.RequestError as e:
59+
print("Could not request results from Google Speech Recognition service; {0}".format(e))
60+
61+
else:
62+
print("Invalid mode selected.")
63+
64+
# Preprocess the text
65+
stop_words = set(stopwords.words('english'))
66+
lemmatizer = WordNetLemmatizer()
67+
tokens = word_tokenize(text)
68+
filtered_tokens = [lemmatizer.lemmatize(w.lower()) for w in tokens if not w.lower() in stop_words]
69+
filtered_text = ' '.join(filtered_tokens)
70+
71+
# Check for profanity in the text using the API
72+
response = requests.get("https://www.purgomalum.com/service/json?text=" + filtered_text)
73+
result = response.json()
74+
75+
if result['result'] == filtered_text:
76+
print("No profanity detected!")
77+
else:
78+
print("Profanity detected!")
79+
print("Censored text: " + result['result'])
80+
81+
# Analyze sentiment of the text using VADER
82+
analyzer = SentimentIntensityAnalyzer()
83+
sentiment_scores = analyzer.polarity_scores(text)
84+
85+
# Print sentiment scores
86+
print("\nSentiment Scores:")
87+
for key, value in sentiment_scores.items():
88+
print(key, ': ', value)
89+
90+
# Print sentiment label based on compound score
91+
sentiment_label = ''
92+
if sentiment_scores['compound'] > 0.5:
93+
sentiment_label = 'Very Positive'
94+
elif sentiment_scores['compound'] > 0:
95+
sentiment_label = 'Positive'
96+
elif sentiment_scores['compound'] == 0:
97+
sentiment_label = 'Neutral'
98+
elif sentiment_scores['compound'] < -0.5:
99+
sentiment_label = 'Very Negative'
100+
else:
101+
sentiment_label = 'Negative'
102+
103+
print("\nSentiment Label: " + sentiment_label)
104+
105+
# Write input and output to CSV file
106+
with open('profanitycheckeroutput.csv', 'a', newline='') as file:
107+
writer = csv.writer(file)
108+
#name the columns
109+
writer.writerow(['Input Text', 'Filtered Text', 'Positive Score', 'Negative Score', 'Neutral Score', 'Compound Score', 'Sentiment Label'])
110+
#write the data
111+
112+
113+
writer.writerow([text, filtered_text, sentiment_scores['pos'], sentiment_scores['neg'], sentiment_scores['neu'], sentiment_scores['compound'], sentiment_label])
114+

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ This repository consists of a list of more than 60 Python scripts, primarily tho
1414

1515
We encourage contributions from the community to make this repository even more valuable. Whether you want to add a new Python script or enhance an existing one, we welcome your input. Here's how you can contribute:
1616

17+
_**Note: Please follow the maintainer of the repository for quick approval of the PR's via [Twitter](https://twitter.com/Dhanush_Nehru), [Instagram](https://www.instagram.com/dhanush_nehru/), [Youtube](https://www.youtube.com/@dhanushnehru?sub_confirmation=1), [Github](https://github.com/DhanushNehru)**_
18+
1719
### Adding a New Script
1820

1921
**1. Create an issue:** Start by creating an issue in this repository. Describe the new script you'd like to contribute, its purpose, and any specific features it will provide.
@@ -79,6 +81,8 @@ More information on contributing and the general code of conduct for discussion
7981
| Planet Simulation | [Planet Simulation](https://github.com/DhanushNehru/Python-Scripts/tree/master/planetSimulation) | A simulation of several planets rotating around the sun. |
8082
| Remove Background | [Remove Background](https://github.com/DhanushNehru/Python-Scripts/tree/master/Remove%20Background) | Removes the background of images. |
8183
| ROCK-PAPER-SCISSOR | [ROCK-PAPER-SCISSOR](https://github.com/DhanushNehru/Python-Scripts/tree/master/ROCK-PAPER-SCISSOR) | A game of Rock Paper Scissors. |
84+
| Random Color Generator | [Random Color Generator](https://github.com/DhanushNehru/Python-Scripts/tree/master/Random%20Color%20Generator) | A random color generator that will show you the color and values!
85+
| Run Then Notify | [Run Then Notify](https://github.com/DhanushNehru/Python-Scripts/tree/master/Run%20Then%20Notify) | Runs a slow command and mails you when it completes execution. |
8286
| Selfie with Python | [Selfie_with_Python](https://github.com/DhanushNehru/Python-Scripts/tree/master/Selfie_with_Python) | Take your selfie with python . |
8387
| Simple TCP Chat Server | [Simple TCP Chat Server](https://github.com/DhanushNehru/Python-Scripts/tree/master/TCP%20Chat%20Server) | Creates a local server on your LAN for receiving and sending messages! |
8488
| Snake Water Gun | [Snake Water Gun](https://github.com/DhanushNehru/Python-Scripts/tree/master/Snake-Water-Gun) | A game similar to Rock Paper Scissors. |
@@ -109,3 +113,7 @@ More information on contributing and the general code of conduct for discussion
109113
<a href="https://github.com/DhanushNehru/Python-Scripts/graphs/contributors">
110114
<img src="https://contrib.rocks/image?repo=DhanushNehru/Python-Scripts" />
111115
</a>
116+
117+
If you liked this repository support it by starring ⭐
118+
119+
Thank You for being here :)

ROCK-PAPER-SCISSOR/rps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
+"paper vs scissor->scissor wins \n")
99

1010
while True:
11-
print("Enter choice \n 1. Rock \n 2. paper \n 3. scissor \n")
11+
print("Enter choice by entering the appropiate number \n 1. Rock \n 2. paper \n 3. scissor \n")
1212

1313
# take the input from user
1414
choice = int(input("User turn: "))

Random Color Generator/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# How to Run
2+
- Make sure you have python 3.8.10 installed
3+
- Make sure you have pygame installed \(How to install [Pygame](#how-to-install-pygame)\)
4+
- Extract Random Color Generator.zip
5+
- Run the program with
6+
```markdown
7+
./Random Color Generator> python RandColorGen.py
8+
```
9+
10+
# How to use
11+
- Click on the window to change colors
12+
- The color values are logged in the console and shown on screen
13+
14+
# How to Install Pygame
15+
- After installing python
16+
- Use pip to install Pygame
17+
```markdown
18+
./wherever> pip install pygame
19+
```
20+
21+
## Dependencies:
22+
- random library
23+
- math library
24+
- pygame library
25+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import pygame
2+
import random
3+
import math
4+
5+
6+
def GenerateRandomColorValue():
7+
r = random.randint(0, 255)
8+
g = random.randint(0, 255)
9+
b = random.randint(0, 255)
10+
11+
return (r, g, b)
12+
13+
14+
def ReturnTextColor(colorValue):
15+
r = colorValue[0]
16+
g = colorValue[1]
17+
b = colorValue[2]
18+
colors = [r, g, b]
19+
20+
i = 0
21+
for c in colors:
22+
c = c / 255.0
23+
if c <= 0.04045:
24+
c = c / 12.92
25+
else:
26+
c = math.pow(((c + 0.055) / 1.055), 2.4)
27+
colors[i] = c
28+
i += 1
29+
30+
r = colors[0]
31+
g = colors[1]
32+
b = colors[2]
33+
34+
L = 0.2126 * r + 0.7152 * g + 0.0722 * b
35+
36+
shouldBeWhite = L > 0.179
37+
# shouldBeWhite = (r * 0.299 + g * 0.587 + b * 0.114) > 186
38+
39+
if shouldBeWhite:
40+
return (0, 0, 0)
41+
else:
42+
return (255, 255, 255)
43+
44+
45+
pygame.init()
46+
47+
height = 500
48+
width = 500
49+
50+
canvas = pygame.display.set_mode((width, height))
51+
pygame.display.set_caption("Random Color Generator!")
52+
isExit = False
53+
canvas.fill((255, 255, 255))
54+
55+
font = pygame.font.Font(pygame.font.get_default_font(), 32)
56+
57+
# RGB Value
58+
RGBText = font.render("RGB Value: (255, 255, 255)", True, (0, 0, 0))
59+
RGBTextRect = RGBText.get_rect()
60+
RGBTextRect.center = (width // 2, height // 2 - 20)
61+
62+
# Hex Value
63+
hexText = font.render("Hex Value: #ffffff", True, (0, 0, 0))
64+
hexTextRect = hexText.get_rect()
65+
hexTextRect.center = (width // 2, height // 2 + 20)
66+
hexTextRect.left = RGBTextRect.left
67+
68+
69+
while not isExit:
70+
canvas.blit(RGBText, RGBTextRect)
71+
canvas.blit(hexText, hexTextRect)
72+
73+
for event in pygame.event.get():
74+
if event.type == pygame.QUIT:
75+
isExit = True
76+
if event.type == pygame.MOUSEBUTTONUP:
77+
color = GenerateRandomColorValue()
78+
RGBString = "RGB Value: " + str(color)
79+
hexString = "Hex Value: " + str("#%02x%02x%02x" % color)
80+
TextColor = ReturnTextColor(color)
81+
RGBText = font.render(RGBString, True, TextColor)
82+
hexText = font.render(hexString, True, TextColor)
83+
print(RGBString + "; " + hexString)
84+
85+
canvas.fill(color)
86+
87+
pygame.display.flip()
Binary file not shown.

Run Then Notify/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Run then Notify
2+
3+
This is a python script that will run any terminal command on a system and once the command successfully runs, it will notify you via email of its time taken and the exit code.
4+
5+
This can be useful in case of long running commands.
6+
7+
Please enter your email and password when prompted. These values are _not_ stored anywhere and are only used for the SMTP connection.
8+
9+
> This system has a hardcoded gmail smtp server specified. In case of any other smtp server, please update the value in code.
10+
>
11+
> **Note**: You may have to enable `less secure app access` in your gmail account.

0 commit comments

Comments
 (0)