Skip to content

Commit a136529

Browse files
First Commit
0 parents  commit a136529

7 files changed

+435
-0
lines changed

covid19_info.py

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# importing tkinter
2+
from tkinter import *
3+
# initializing tkinter
4+
root = Tk()
5+
# setting geometry
6+
root.geometry("350x350")
7+
# setting title
8+
root.title("Get Covid-19 Data Country Wise")
9+
10+
# function which will get covid data and will show it
11+
def showdata():
12+
# importing matplotlib which will be used to show data graphically
13+
from matplotlib import pyplot as plt
14+
# to scale the data we are importing patches
15+
import matplotlib.patches as mpatches
16+
# importing covid library
17+
from covid import Covid
18+
# initializing covid library
19+
covid = Covid()
20+
# declaring empty lists to store different data sets
21+
cases = []
22+
confirmed = []
23+
active = []
24+
deaths = []
25+
recovered = []
26+
# using try and except to run program without errors
27+
try:
28+
# updating root
29+
root.update()
30+
# getting countries names entered by the user
31+
countries = data.get()
32+
# removing white spaces from the start and end of the string
33+
country_names = countries.strip()
34+
# replacing white spaces with commas inside the string
35+
country_names = country_names.replace(" ", ",")
36+
# splitting the string to store names of countries
37+
# as a list
38+
country_names = country_names.split(",")
39+
# for loop to get all countries data
40+
for x in country_names:
41+
# appending countries data one-by-one in cases list
42+
# here, the data will be stored as a dictionary
43+
# for one country i.e. for each country
44+
# there will be one dictionary in the list
45+
# which will contain the whole information
46+
# of that country
47+
cases.append(covid.get_status_by_country_name(x))
48+
# updating the root
49+
root.update()
50+
# for loop to get one country data stored as dict in list cases
51+
for y in cases:
52+
# storing every Country's confirmed cases in the confirmed list
53+
confirmed.append(y["confirmed"])
54+
# storing every Country's active cases in the active list
55+
active.append(y["active"])
56+
# storing every Country's deaths cases in the deaths list
57+
deaths.append(y["deaths"])
58+
# storing every Country's recovered cases in the recovered list
59+
recovered.append(y["recovered"])
60+
# marking the color information on scaleusing patches
61+
confirmed_patch = mpatches.Patch(color='green', label='confirmed')
62+
recovered_patch = mpatches.Patch(color='red', label='recovered')
63+
active_patch = mpatches.Patch(color='blue', label='active')
64+
deaths_patch = mpatches.Patch(color='black', label='deaths')
65+
# plotting the scale on graph using legend()
66+
plt.legend(handles=[confirmed_patch, recovered_patch, active_patch, deaths_patch])
67+
# showing the data using graphs
68+
# this whole for loop section is related to matplotlib
69+
for x in range(len(country_names)):
70+
plt.bar(country_names[x], confirmed[x], color='green')
71+
if recovered[x] > active[x]:
72+
plt.bar(country_names[x], recovered[x], color='red')
73+
plt.bar(country_names[x], active[x], color='blue')
74+
else:
75+
plt.bar(country_names[x], active[x], color='blue')
76+
plt.bar(country_names[x], recovered[x], color='red')
77+
plt.bar(country_names[x], deaths[x], color='black')
78+
# setting the title of the graph
79+
plt.title('Current Covid Cases')
80+
# giving label to x direction of graph
81+
plt.xlabel('Country Name')
82+
# giving label to y direction of graph
83+
plt.ylabel('Cases(in millions)')
84+
# showing the full graph
85+
plt.show()
86+
except Exception as e:
87+
# asking user to enter correct details
88+
# during entering the country names on GUI
89+
# please differentiate the country names
90+
# with spaces or comma but not with both
91+
# otherwise you will come to this section
92+
data.set("Enter correct details again")
93+
94+
95+
Label(root, text="Enter all countries names\nfor whom you want to get\ncovid-19 data", font="Consolas 15 bold").pack()
96+
Label(root, text="Enter country name:").pack()
97+
data = StringVar()
98+
data.set("Seperate country names using comma or space(not both)")
99+
entry = Entry(root, textvariable=data, width=50).pack()
100+
Button(root, text="Get Data", command=showdata).pack()
101+
root.mainloop()

grey camera.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
import cv2
3+
4+
capture = cv2.VideoCapture(0)
5+
6+
while(True):
7+
8+
ret, frame = capture.read()
9+
10+
grayFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
11+
12+
cv2.imshow('video gray', grayFrame)
13+
14+
15+
if cv2.waitKey(1) == 27:
16+
break
17+
18+
capture.release()
19+
cv2.destroyAllWindows()

snake_game.py

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import pygame
2+
import random
3+
# initializing pygame
4+
pygame.init()
5+
6+
# Colors
7+
white = (255, 255, 255) # rgb format
8+
red = (255, 0, 0)
9+
black = (0, 0, 0)
10+
11+
# Creating window
12+
screen_width = 900
13+
screen_height = 600
14+
gameWindow = pygame.display.set_mode((screen_width, screen_height))
15+
16+
# Game Title
17+
pygame.display.set_caption("Coders Home")
18+
pygame.display.update()
19+
clock = pygame.time.Clock()
20+
font = pygame.font.SysFont(None, 55)
21+
22+
def text_screen(text, color, x, y):
23+
screen_text = font.render(text, True, color)
24+
gameWindow.blit(screen_text, [x,y])
25+
26+
27+
def plot_snake(gameWindow, color, snk_list, snake_size):
28+
for x,y in snk_list:
29+
pygame.draw.rect(gameWindow, color, [x, y, snake_size, snake_size])
30+
31+
# Game Loop
32+
def gameloop():
33+
exit_game = False
34+
game_over = False
35+
snake_x = 45
36+
snake_y = 55
37+
velocity_x = 0
38+
velocity_y = 0
39+
snk_list = []
40+
snk_length = 1
41+
42+
food_x = random.randint(20, screen_width-20)
43+
food_y = random.randint(60, screen_height -20)
44+
score = 0
45+
init_velocity = 4
46+
snake_size = 30
47+
fps = 60 # fps = frames per second
48+
while not exit_game:
49+
if game_over:
50+
gameWindow.fill(white)
51+
text_screen("Game Over! Press Enter To Continue", red, 100, 250)
52+
53+
for event in pygame.event.get():
54+
if event.type == pygame.QUIT:
55+
exit_game = True
56+
57+
if event.type == pygame.KEYDOWN:
58+
if event.key == pygame.K_RETURN:
59+
gameloop()
60+
61+
else:
62+
63+
for event in pygame.event.get():
64+
if event.type == pygame.QUIT:
65+
exit_game = True
66+
67+
if event.type == pygame.KEYDOWN:
68+
if event.key == pygame.K_RIGHT:
69+
velocity_x = init_velocity
70+
velocity_y = 0
71+
72+
if event.key == pygame.K_LEFT:
73+
velocity_x = - init_velocity
74+
velocity_y = 0
75+
76+
if event.key == pygame.K_UP:
77+
velocity_y = - init_velocity
78+
velocity_x = 0
79+
80+
if event.key == pygame.K_DOWN:
81+
velocity_y = init_velocity
82+
velocity_x = 0
83+
84+
snake_x = snake_x + velocity_x
85+
snake_y = snake_y + velocity_y
86+
87+
if abs(snake_x - food_x)<10 and abs(snake_y - food_y)<10:
88+
score +=1
89+
food_x = random.randint(20, screen_width - 30)
90+
food_y = random.randint(60, screen_height - 30)
91+
snk_length +=5
92+
93+
gameWindow.fill(white)
94+
text_screen("Score: " + str(score * 10), red, 5, 5)
95+
pygame.draw.rect(gameWindow, red, [food_x, food_y, snake_size, snake_size])
96+
pygame.draw.line(gameWindow, red, (0,40), (900,40),5)
97+
98+
head = []
99+
head.append(snake_x)
100+
head.append(snake_y)
101+
snk_list.append(head)
102+
103+
if len(snk_list)>snk_length:
104+
del snk_list[0]
105+
106+
if head in snk_list[:-1]:
107+
game_over = True
108+
109+
if snake_x<0 or snake_x>screen_width-20 or snake_y<50 or snake_y>screen_height-20:
110+
game_over = True
111+
plot_snake(gameWindow, black, snk_list, snake_size)
112+
pygame.display.update()
113+
clock.tick(fps)
114+
pygame.quit()
115+
quit()
116+
gameloop()

speech to text.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Python program to translate
2+
# speech to text and text to speech
3+
4+
5+
import speech_recognition as sr
6+
import pyttsx3
7+
8+
# Initialize the recognizer
9+
r = sr.Recognizer()
10+
11+
# Function to convert text to
12+
# speech
13+
def SpeakText(command):
14+
15+
# Initialize the engine
16+
engine = pyttsx3.init()
17+
engine.say(command)
18+
engine.runAndWait()
19+
20+
21+
# Loop infinitely for user to
22+
# speak
23+
24+
while(1):
25+
26+
# Exception handling to handle
27+
# exceptions at the runtime
28+
try:
29+
30+
# use the microphone as source for input.
31+
with sr.Microphone() as source2:
32+
33+
# wait for a second to let the recognizer
34+
# adjust the energy threshold based on
35+
# the surrounding noise level
36+
r.adjust_for_ambient_noise(source2, duration=0.2)
37+
38+
#listens for the user's input
39+
audio2 = r.listen(source2)
40+
41+
# Using ggogle to recognize audio
42+
MyText = r.recognize_google(audio2)
43+
MyText = MyText.lower()
44+
45+
print("Did you say "+MyText)
46+
SpeakText(MyText)
47+
48+
except sr.RequestError as e:
49+
print("Could not request results; {0}".format(e))
50+
51+
except sr.UnknownValueError:
52+
print("unknown error occured")

surfing web with speech.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import speech_recognition as sr
2+
import webbrowser
3+
4+
5+
6+
sr.Microphone(device_index=1)
7+
r=sr.Recognizer()
8+
r.energy_threshold=5000
9+
10+
with sr.Microphone() as source:
11+
12+
print("speak!")
13+
audio=r.listen(source)
14+
15+
try:
16+
17+
text=r.recognize_google(audio)
18+
print("You said : {}".format(text))
19+
url='https://www.google.com/search?q='
20+
search_url=url+text
21+
webbrowser.open(search_url)
22+
23+
except:
24+
print("Can't recognize")
25+
26+
27+
28+
29+
30+

text to speech.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pyttsx3
2+
engine=pyttsx3.init()
3+
a=5
4+
while a>0:
5+
6+
text=input("Enter the text:-" )
7+
engine.say(text)
8+
engine.runAndWait()

0 commit comments

Comments
 (0)