Skip to content

Instantly share code, notes, and snippets.

View zakirangwala's full-sized avatar
🐛
squashing bugs

Zaki Rangwala zakirangwala

🐛
squashing bugs
View GitHub Profile
@zakirangwala
zakirangwala / speak.py
Last active September 23, 2020 12:32
Tutorial code : Speak Function using the pyttsx3 package
import pyttsx3
# Initialize Text to Speech
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
# Speak Function
def speak(audio):
engine.say(audio)
@zakirangwala
zakirangwala / speak.py
Last active September 23, 2020 12:33
Tutorial code : Speak Function using the gTTS package
# Import required modules for Text to speech conversion
from gtts import gTTS
import playsound
import os
#Speak Function
def speak():
engine = gTTS(text='Hello World', lang='en', slow=False)
engine.save("speech.mp3")
playsound.playsound("speech.mp3")
@zakirangwala
zakirangwala / listen.py
Last active September 23, 2020 13:06
Tutorial code : Listen Function
import speech_recognition as sr
# Listen to user input
def listen():
r = sr.Recognizer()
with sr.Microphone() as source:
speak("I'm Listening")
print("Listening...")
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
@zakirangwala
zakirangwala / greet.py
Last active September 23, 2020 13:26
Tutorial Code : Greet Function
import datetime
# Greeting Function
def greet():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour <= 12:
speak("Good Morning!")
print("Good Morning!")
elif hour > 12 and hour < 16:
speak("Good Afternoon!")
@zakirangwala
zakirangwala / stock_price.py
Created September 23, 2020 12:56
Tutorial Code : Stock Price Real-Time
# Import libraries
from bs4 import BeautifulSoup
import requests
# Configure Browser Header and URL
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'}
URL = ''
# Check Price of stock
@zakirangwala
zakirangwala / google_query.py
Created September 23, 2020 13:17
Tutorial Code : Make Google Query
# Import Search module
from googlesearch import search
# Make Google Query
def google_query(query):
link = []
for j in search(query, tld="ca", num=10, stop=10, pause=2):
link.append(j)
return link
@zakirangwala
zakirangwala / get_location.py
Created September 23, 2020 13:44
Tutorial Code : Get user location
# Get location
def get_location():
try:
URL = 'https://iplocation.com/'
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
city = soup.find(class_='city').get_text()
country = soup.find(class_='country_name').get_text()
latitude = soup.find(class_='lat').get_text()
longitude = soup.find(class_='lng').get_text()
@zakirangwala
zakirangwala / weather.py
Created September 23, 2020 14:03
Tutorial code : Get weather data
import config
# Check Weather
def weather(latitude, longitude):
try:
api_key = config.api_key
base_url = 'http://api.openweathermap.org/data/2.5/weather?'
complete_url = base_url + "lat=" + \
str(latitude) + "&lon=" + str(longitude) + "&appid=" + api_key
response = requests.get(complete_url)
x = response.json()
@zakirangwala
zakirangwala / movie.py
Last active September 23, 2020 14:18
Tutorial Code : Scrape web for IMDB movie link
import imdb
# Find IMDB
def find_imdb(query):
try:
query += ' IMDB'
URL = google_query(query)[0]
page = requests.get(URL, headers=headers)
html_content = page.text
soup = BeautifulSoup(html_content, 'lxml')
@zakirangwala
zakirangwala / rotten_tomatoes_score.py
Created September 23, 2020 14:21
Tutorial Code : Get the rotten tomato score of a movie
# Rotten Tomatoes Score
def rotten_tomatoes_score(query):
try:
query += query + " Rotten Tomatoes"
URL = google_query(query)[0]
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
res = soup.find(class_='mop-ratings-wrap__percentage').get_text()
check = res.split(' ')
for i in check: