Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c82080d

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in 6c21609 according to the output from Autopep8. Details: https://app.deepsource.com/gh/avinashkranjan/Amazing-Python-Scripts/transform/e35a1f84-7fc5-4d95-9daf-ffe63cd9c56c/
1 parent a5049a4 commit c82080d

File tree

1 file changed

+142
-148
lines changed
  • VoxiDesk-Smart Desktop Assistant

1 file changed

+142
-148
lines changed

‎VoxiDesk-Smart Desktop Assistant/main.py

Lines changed: 142 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,47 @@
1818
voices = engine.getProperty('voices')
1919
engine.setProperty('voice', voices[1].id)
2020

21+
2122
def talk(text):
2223
engine.say(text)
2324
engine.runAndWait()
2425

26+
2527
talk('Hello buddy , What can i help you')
26-
def take_command():
28+
29+
30+
def take_command():
2731
try:
2832
with sr.Microphone() as source:
2933
print('listening...')
3034
voice = listener.listen(source)
3135
command = listener.recognize_google(voice)
32-
command =command.lower()
36+
command =command.lower()
3337
if 'nova' in command:
3438
command = command.replace('nova', '')
3539
print(command)
3640
except:
3741
pass
3842
return command
3943

44+
4045
def run_alexa():
41-
command =take_command()
46+
command =take_command()
4247
print(command)
4348

44-
#play song on youtube
49+
#play song on youtube
4550
if 'play' in command:
4651
song = command.replace('play', '')
4752
talk('playing' + song)
4853
pywhatkit.playonyt(song)
4954

50-
#Current time
55+
#Current time
5156
elif 'time' in command:
5257
time = datetime.datetime.now().strftime('%H:%M')
5358
print(time)
54-
talk('Current time is '+ time)
59+
talk('Current time is '+ time)
5560

56-
#wikipedia answer
61+
#wikipedia answer
5762
elif 'what is' in command:
5863
person = command.replace('See', '')
5964
info = wikipedia.summary(person, 2)
@@ -70,176 +75,165 @@ def run_alexa():
7075
print(info)
7176
talk(info)
7277

73-
#fun with nova
78+
#fun with nova
7479
elif 'i love you' in command:
7580
talk('i love you too')
7681
elif 'what are you doing' in command:
7782
talk('I am talking to you')
7883
elif 'are you single' in command:
7984
talk('I am relationship with wifi')
80-
85+
8186
elif 'joke' in command:
8287
print(pyjokes.get_joke())
8388
talk(pyjokes.get_joke())
8489

85-
#current location
90+
#current location
8691
elif 'location' in command:
8792
g = geocoder.ip('me')
8893
print(g.city)
8994
talk('your current location is' + g.city)
9095

91-
#take a screen shot
96+
#take a screen shot
9297
elif 'screenshot' in command:
9398
im = pyautogui.screenshot()
9499
im.save("SS1.jpg")
95100

96-
#Take some photo
101+
#Take some photo
97102
elif 'take a photo' in command:
98-
pygame.camera.init()
99-
camlist = pygame.camera.list_cameras()
100-
if camlist:
101-
cam = pygame.camera.Camera(camlist[0], (640, 480))
102-
cam.start()
103-
image = cam.get_image()
104-
pygame.image.save(image, "filename.jpg")
105-
else:
106-
print("No camera on current device")
107-
108-
109-
#play snake game
103+
pygame.camera.init()
104+
camlist = pygame.camera.list_cameras()
105+
if camlist:
106+
cam = pygame.camera.Camera(camlist[0], (640, 480))
107+
cam.start()
108+
image = cam.get_image()
109+
pygame.image.save(image, "filename.jpg")
110+
else:
111+
print("No camera on current device")
112+
113+
# play snake game
110114
elif 'snake game' in command:
111-
w = 500
112-
h = 500
113-
food_size = 10
114-
delay = 100
115-
116-
offsets = {
117-
"up": (0, 20),
118-
"down": (0, -20),
119-
"left": (-20, 0),
120-
"right": (20, 0)
121-
}
122-
123-
def reset():
124-
global snake, snake_dir, food_position, pen
125-
snake = [[0, 0], [0, 20], [0, 40], [0, 60], [0, 80]]
126-
snake_dir = "up"
127-
food_position = get_random_food_position()
128-
food.goto(food_position)
129-
move_snake()
130-
131-
def move_snake():
132-
global snake_dir
133-
134-
new_head = snake[-1].copy()
135-
new_head[0] = snake[-1][0] + offsets[snake_dir][0]
136-
new_head[1] = snake[-1][1] + offsets[snake_dir][1]
137-
138-
139-
if new_head in snake[:-1]:
140-
reset()
141-
else:
142-
snake.append(new_head)
143-
144-
145-
if not food_collision():
146-
snake.pop(0)
147-
148-
149-
if snake[-1][0] > w / 2:
150-
snake[-1][0] -= w
151-
elif snake[-1][0] < - w / 2:
152-
snake[-1][0] += w
153-
elif snake[-1][1] > h / 2:
154-
snake[-1][1] -= h
155-
elif snake[-1][1] < -h / 2:
156-
snake[-1][1] += h
157-
158-
159-
pen.clearstamps()
160-
161-
162-
for segment in snake:
163-
pen.goto(segment[0], segment[1])
164-
pen.stamp()
165-
166-
167-
screen.update()
168-
169-
turtle.ontimer(move_snake, delay)
170-
171-
def food_collision():
172-
global food_position
173-
if get_distance(snake[-1], food_position) < 20:
174-
food_position = get_random_food_position()
175-
food.goto(food_position)
176-
return True
177-
return False
178-
179-
def get_random_food_position():
180-
x = random.randint(- w / 2 + food_size, w / 2 - food_size)
181-
y = random.randint(- h / 2 + food_size, h / 2 - food_size)
182-
return (x, y)
183-
184-
def get_distance(pos1, pos2):
185-
x1, y1 = pos1
186-
x2, y2 = pos2
187-
distance = ((y2 - y1) ** 2 + (x2 - x1) ** 2) ** 0.5
188-
return distance
189-
def go_up():
190-
global snake_dir
191-
if snake_dir != "down":
192-
snake_dir = "up"
193-
194-
def go_right():
195-
global snake_dir
196-
if snake_dir != "left":
197-
snake_dir = "right"
198-
199-
def go_down():
200-
global snake_dir
201-
if snake_dir!= "up":
202-
snake_dir = "down"
203-
204-
def go_left():
205-
global snake_dir
206-
if snake_dir != "right":
207-
snake_dir = "left"
208-
209-
210-
screen = turtle.Screen()
211-
screen.setup(w, h)
212-
screen.title("Snake")
213-
screen.bgcolor("blue")
214-
screen.setup(500, 500)
215-
screen.tracer(0)
216-
217-
218-
pen = turtle.Turtle("square")
219-
pen.penup()
115+
w = 500
116+
h = 500
117+
food_size = 10
118+
delay = 100
119+
120+
offsets = {
121+
"up": (0, 20),
122+
"down": (0, -20),
123+
"left": (-20, 0),
124+
"right": (20, 0)
125+
}
126+
127+
def reset():
128+
global snake, snake_dir, food_position, pen
129+
snake = [[0, 0], [0, 20], [0, 40], [0, 60], [0, 80]]
130+
snake_dir = "up"
131+
food_position = get_random_food_position()
132+
food.goto(food_position)
133+
move_snake()
134+
135+
def move_snake():
136+
global snake_dir
137+
138+
new_head = snake[-1].copy()
139+
new_head[0] = snake[-1][0] + offsets[snake_dir][0]
140+
new_head[1] = snake[-1][1] + offsets[snake_dir][1]
141+
142+
if new_head in snake[:-1]:
143+
reset()
144+
else:
145+
snake.append(new_head)
220146

147+
if not food_collision():
148+
snake.pop(0)
221149

222-
food = turtle.Turtle()
223-
food.shape("square")
224-
food.color("yellow")
225-
food.shapesize(food_size / 20)
226-
food.penup()
150+
if snake[-1][0] > w / 2:
151+
snake[-1][0] -= w
152+
elif snake[-1][0] < - w / 2:
153+
snake[-1][0] += w
154+
elif snake[-1][1] > h / 2:
155+
snake[-1][1] -= h
156+
elif snake[-1][1] < -h / 2:
157+
snake[-1][1] += h
227158

159+
pen.clearstamps()
228160

229-
screen.listen()
230-
screen.onkey(go_up, "Up")
231-
screen.onkey(go_right, "Right")
232-
screen.onkey(go_down, "Down")
233-
screen.onkey(go_left, "Left")
161+
for segment in snake:
162+
pen.goto(segment[0], segment[1])
163+
pen.stamp()
234164

165+
screen.update()
235166

236-
reset()
237-
turtle.done()
167+
turtle.ontimer(move_snake, delay)
238168

169+
def food_collision():
170+
global food_position
171+
if get_distance(snake[-1], food_position) < 20:
172+
food_position = get_random_food_position()
173+
food.goto(food_position)
174+
return True
175+
return False
176+
177+
def get_random_food_position():
178+
x = random.randint(- w / 2 + food_size, w / 2 - food_size)
179+
y = random.randint(- h / 2 + food_size, h / 2 - food_size)
180+
return (x, y)
181+
182+
def get_distance(pos1, pos2):
183+
x1, y1 = pos1
184+
x2, y2 = pos2
185+
distance = ((y2 - y1) ** 2 + (x2 - x1) ** 2) ** 0.5
186+
return distance
187+
188+
def go_up():
189+
global snake_dir
190+
if snake_dir != "down":
191+
snake_dir = "up"
239192

240-
#any command doesn't match nova talk this line
193+
def go_right():
194+
global snake_dir
195+
if snake_dir != "left":
196+
snake_dir = "right"
197+
198+
def go_down():
199+
global snake_dir
200+
if snake_dir != "up":
201+
snake_dir = "down"
202+
203+
def go_left():
204+
global snake_dir
205+
if snake_dir != "right":
206+
snake_dir = "left"
207+
208+
screen = turtle.Screen()
209+
screen.setup(w, h)
210+
screen.title("Snake")
211+
screen.bgcolor("blue")
212+
screen.setup(500, 500)
213+
screen.tracer(0)
214+
215+
pen = turtle.Turtle("square")
216+
pen.penup()
217+
218+
food = turtle.Turtle()
219+
food.shape("square")
220+
food.color("yellow")
221+
food.shapesize(food_size / 20)
222+
food.penup()
223+
224+
screen.listen()
225+
screen.onkey(go_up, "Up")
226+
screen.onkey(go_right, "Right")
227+
screen.onkey(go_down, "Down")
228+
screen.onkey(go_left, "Left")
229+
230+
reset()
231+
turtle.done()
232+
233+
# any command doesn't match nova talk this line
241234
else:
242235
talk('Please say the command again.')
243-
236+
237+
244238
while True:
245-
run_alexa()
239+
run_alexa()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /