Skip to content

Commit 5b72300

Browse files
Merge pull request #2095 from NitkarshChourasia/testing
add/update: New program to automate sending messages.
2 parents 6377bd9 + dd10333 commit 5b72300

13 files changed

+284
-91
lines changed

area_of_square_app.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
__author__ = "Nitkarsh Chourasia"
2+
__author_GitHub_profile__ = "https://github.com/NitkarshChourasia"
3+
__author_email_address__ = "[email protected]"
4+
__created_on__ = "10/10/2021"
5+
__last_updated__ = "10/10/2021"
6+
7+
from word2number import w2n
8+
9+
10+
def convert_words_to_number(word_str):
11+
"""
12+
Convert a string containing number words to an integer.
13+
14+
Args:
15+
- word_str (str): Input string with number words.
16+
17+
Returns:
18+
- int: Numeric equivalent of the input string.
19+
"""
20+
numeric_result = w2n.word_to_num(word_str)
21+
return numeric_result
22+
23+
24+
# Example usage:
25+
number_str = "two hundred fifteen"
26+
result = convert_words_to_number(number_str)
27+
print(result) # Output: 215
28+
29+
30+
class Square:
31+
def __init__(self, side=None):
32+
if side is None:
33+
self.ask_side()
34+
# else:
35+
# self.side = float(side)
36+
else:
37+
if not isinstance(side, (int, float)):
38+
try:
39+
side = float(side)
40+
except ValueError:
41+
# return "Invalid input for side."
42+
raise ValueError("Invalid input for side.")
43+
else:
44+
self.side = float(side)
45+
# Check if the result is a float and remove unnecessary zeros
46+
47+
self.calculate_square()
48+
self.truncate_decimals()
49+
50+
# If ask side or input directly into the square.
51+
# That can be done?
52+
def calculate_square(self):
53+
self.area = self.side * self.side
54+
return self.area
55+
56+
# Want to add a while loop asking for the input.
57+
# Also have an option to ask the user in true mode or in repeat mode.
58+
def ask_side(self):
59+
# if true bool then while if int or float then for loop.
60+
# I will have to learn inheritance and polymorphism.
61+
condition = 3
62+
# condition = True
63+
if condition == True and isinstance(condition, bool):
64+
while condition:
65+
n = input("Enter the side of the square: ")
66+
self.side = float(n)
67+
elif isinstance(condition, (int, float)):
68+
for i in range(_=condition):
69+
n = input("Enter the side of the square: ")
70+
self.side = float(n)
71+
# n = input("Enter the side of the square: ")
72+
# self.side = float(n)
73+
# return
74+
75+
def truncate_decimals(self):
76+
return (
77+
f"{self.area:.10f}".rstrip("0").rstrip(".")
78+
if "." in str(self.area)
79+
else self.area
80+
)
81+
82+
# Prettifying the output.
83+
84+
def calculate_perimeter(self):
85+
return 4 * self.side
86+
87+
def calculate_perimeter_prettify(self):
88+
return f"The perimeter of the square is {self.calculate_perimeter()}."
89+
90+
def calculate_area_prettify(self):
91+
return f"The area of the square is {self.area}."
92+
93+
def truncate_decimals_prettify(self):
94+
return f"The area of the square is {self.truncate_decimals()}."
95+
96+
97+
if __name__ == "__main__":
98+
output_one = Square()
99+
truncated_area = output_one.truncate_decimals()
100+
# print(output_one.truncate_decimals())
101+
print(truncated_area)
102+
103+
104+
# add a while loop to keep asking for the user input.
105+
# also make sure to add a about menu to input a while loop in tkinter app.
106+
107+
# It can use a beautiful GUI also.
108+
# Even validation is left.
109+
# What if string is provided in number? Then?
110+
# What if chars are provided. Then?
111+
# What if a negative number is provided? Then?
112+
# What if a number is provided in alphabets characters? Then?
113+
# Can it a single method have more object in it?
114+
115+
# Also need to perform testing on it.
116+
# EXTREME FORM OF TESTING NEED TO BE PERFORMED ON IT.
117+
# Documentation is also needed.
118+
# Comments are also needed.
119+
# TYPE hints are also needed.
120+
121+
# README.md file is also needed.
122+
## Which will explain the whole project.
123+
### Like how to use the application.
124+
### List down the features in explicit detail.
125+
### How to use different methods and classes.
126+
### It will also a image of the project in working state.
127+
### It will also have a video to the project in working state.
128+
129+
# It should also have .exe and linux executable file.
130+
# It should also be installable into Windows(x86) system and if possible into Linux system also.

sWAP_cASE.py

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

send_message_automation/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Send message automation
2+
3+
4+
sources used:
5+
6+
7+
Gif image creation credit goes to:
8+
- ezgif.com used to make gif images.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
__ _ _ _ _ ___ _ _
3+
/\ \ \(_)| |_ | | __ __ _ _ __ ___ | |__ / __\| |__ ___ _ _ _ __ __ _ ___ (_) __ _
4+
/ \/ /| || __|| |/ / / _` || '__|/ __|| '_ \ / / | '_ \ / _ \ | | | || '__| / _` |/ __|| | / _` |
5+
/ /\ / | || |_ | < | (_| || | \__ \| | | | / /___ | | | || (_) || |_| || | | (_| |\__ \| || (_| |
6+
\_\ \/ |_| \__||_|\_\ \__,_||_| |___/|_| |_| \____/ |_| |_| \___/ \__,_||_| \__,_||___/|_| \__,_|
7+
Binary file not shown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pyautogui
2+
from time import sleep
3+
4+
# Do you want to include the message counter?
5+
# make a class of it.
6+
7+
# Can make a broswer session open and navigating to web.whatsapp
8+
# os dependencies and browser dependencies and default browser if none
9+
# also check for whatsapp on the system
10+
11+
12+
def send_message(message):
13+
pyautogui.write(message)
14+
pyautogui.press("enter")
15+
16+
17+
def send_repeatedly(message, repetitions, delay):
18+
count = 1
19+
try:
20+
for _ in range(repetitions):
21+
send_message(f"Message {count}: {message}")
22+
sleep(delay)
23+
count += 1
24+
except KeyboardInterrupt:
25+
print("\nProgram terminated by user.")
26+
27+
28+
if __name__ == "__main__":
29+
try:
30+
user_message = input("Enter the message you want to send: ")
31+
repetitions = int(input("Enter the number of repetitions: "))
32+
delay = float(input("Enter the delay between messages (in seconds): "))
33+
34+
sleep(5)
35+
send_repeatedly(user_message, repetitions, delay)
36+
37+
except ValueError:
38+
print("Invalid input. Please enter a valid number.")
39+
40+
except Exception as e:
41+
print(f"An error occurred: {str(e)}")
743 KB
Loading
Binary file not shown.

turtle_shapes_made.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import turtle
2+
3+
class ShapeDrawer:
4+
def __init__(self, color, pensize):
5+
self.turtle = turtle.Turtle()
6+
self.turtle.color(color)
7+
self.turtle.pensize(pensize)
8+
9+
def draw_rectangle(self, width, height):
10+
for _ in range(2):
11+
self.turtle.forward(width)
12+
self.turtle.left(90)
13+
self.turtle.forward(height)
14+
self.turtle.left(90)
15+
16+
def draw_triangle(self, length):
17+
for _ in range(3):
18+
self.turtle.forward(length)
19+
self.turtle.left(120)
20+
21+
def main():
22+
scrn = turtle.Screen()
23+
scrn.bgcolor("lavender")
24+
25+
# Draw Rectangle
26+
rectangle_drawer = ShapeDrawer("blue", 3)
27+
rectangle_drawer.draw_rectangle(180, 75)
28+
29+
# Draw Triangle
30+
triangle_drawer = ShapeDrawer("hot pink", 4)
31+
triangle_drawer.turtle.penup()
32+
triangle_drawer.turtle.goto(-90, -75)
33+
triangle_drawer.turtle.pendown()
34+
triangle_drawer.draw_triangle(100)
35+
36+
# Add more drawings as needed
37+
# ...
38+
39+
# Example: Draw a circle
40+
circle_drawer = ShapeDrawer("green", 2)
41+
circle_drawer.turtle.penup()
42+
circle_drawer.turtle.goto(0, 0)
43+
circle_drawer.turtle.pendown()
44+
circle_drawer.turtle.circle(50)
45+
46+
scrn.exitonclick()
47+
48+
if __name__ == "__main__":
49+
main()

tweeter.py

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,72 @@
1-
"""
2-
Author: Shreyas Daniel (shreydan)
3-
Install: tweepy - "pip install tweepy"
4-
API: Create a twitter app "apps.twitter.com" to get your OAuth requirements.
5-
Version: 1.0
6-
7-
Tweet text and pics directly from the terminal.
8-
"""
91
from __future__ import print_function
10-
112
import os
12-
133
import tweepy
144

15-
try:
16-
input = raw_input
17-
except NameError:
18-
pass
5+
# TODO: Further improvements can be made to the program
6+
# TODO: Further feature improvements and Refactoring can be done to the program
7+
# TODO: Add a README.md file showcasing how adding it to the PATH variable can make the posting much easier
198

209

21-
def getStatus():
10+
def get_status():
2211
lines = []
2312
while True:
2413
line = input()
2514
if line:
2615
lines.append(line)
2716
else:
2817
break
29-
status = "\n".join(lines)
30-
return status
18+
return "\n".join(lines)
3119

3220

33-
def tweetthis(type):
34-
if type == "text":
35-
print("Enter your tweet " + user.name)
36-
tweet = getStatus()
37-
try:
38-
api.update_status(tweet)
39-
except Exception as e:
40-
print(e)
41-
return
42-
elif type == "pic":
43-
print("Enter pic path " + user.name)
44-
pic = os.path.abspath(input())
45-
print("Enter status " + user.name)
46-
title = getStatus()
47-
try:
48-
api.update_with_media(pic, status=title)
49-
except Exception as e:
50-
print(e)
51-
return
21+
def tweet_text(api, user):
22+
print(f"Enter your tweet, {user.name}:")
23+
tweet = get_status()
24+
try:
25+
api.update_status(tweet)
26+
print("\nTweet posted successfully!")
27+
except tweepy.TweepError as e:
28+
print(f"Error posting tweet: {e}")
5229

53-
print("\n\nDONE!!")
5430

31+
def tweet_picture(api, user):
32+
print(f"Enter the picture path, {user.name}:")
33+
pic = os.path.abspath(input())
34+
print(f"Enter the status, {user.name}:")
35+
title = get_status()
36+
try:
37+
api.update_with_media(pic, status=title)
38+
print("\nTweet with picture posted successfully!")
39+
except tweepy.TweepError as e:
40+
print(f"Error posting tweet with picture: {e}")
5541

56-
def initialize():
57-
global api, auth, user
58-
ck = "here" # consumer key
59-
cks = "here" # consumer key SECRET
60-
at = "here" # access token
61-
ats = "here" # access token SECRET
42+
43+
def initialize_api():
44+
ck = "your_consumer_key"
45+
cks = "your_consumer_key_secret"
46+
at = "your_access_token"
47+
ats = "your_access_token_secret"
6248

6349
auth = tweepy.OAuthHandler(ck, cks)
6450
auth.set_access_token(at, ats)
65-
6651
api = tweepy.API(auth)
6752
user = api.me()
53+
return api, user
6854

6955

7056
def main():
71-
doit = int(input("\n1. text\n2. picture\n"))
72-
initialize()
73-
if doit == 1:
74-
tweetthis("text")
75-
elif doit == 2:
76-
tweetthis("pic")
77-
else:
78-
print("OK, Let's try again!")
79-
main()
57+
try:
58+
doit = int(input("\n1. Text\n2. Picture\nChoose option (1/2): "))
59+
api, user = initialize_api()
60+
61+
if doit == 1:
62+
tweet_text(api, user)
63+
elif doit == 2:
64+
tweet_picture(api, user)
65+
else:
66+
print("Invalid option. Please choose 1 or 2.")
67+
except ValueError:
68+
print("Invalid input. Please enter a valid number.")
8069

8170

82-
main()
71+
if __name__ == "__main__":
72+
main()

0 commit comments

Comments
 (0)