Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added IMDb #1473

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions 33. Python Programs/IMDb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-

import datetime
import time

import requests


def imdb():
"""A program that fetches information related to movies/tv shows from the Internet Movie Database"""
imdbtoken = "" # You can get this API token from here -> https://www.omdbapi.com/apikey.aspx
query = str(input("Enter the name of the show or the movie: "))
if query == "":
print("\nYou need to enter a search query!")
time.sleep(10)
exit()

start = datetime.datetime.now()
print("\nConnecting...\n")
query = query.replace(" ","+")
api = f"https://www.omdbapi.com/?t={query}&plot=full&apikey={imdbtoken}"

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/41.0.2228.0 Safari/537.36'}

r = requests.get(api, headers=headers)
if r.status_code != 200:
print("Connection Failed D:")
time.sleep(3)
exit()

print("Connected!\n\n")

result = r.json()
for key, value in result.items():
if type(value) is not list:
print (key, value, sep=" - ")
else:
pass

end = datetime.datetime.now()
total_time = (end - start).total_seconds()
print(f"\nDone!")

input(f"Total time taken : {total_time} seconds")

if __name__ == '__main__':
imdb()
82 changes: 82 additions & 0 deletions 33. Python Programs/Weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-

import datetime
import time

import requests



def weather():
"""A simple program that fetches weather information for the provided location"""
city = ""
city = str(input("Enter the name of the city: "))
start = datetime.datetime.now()
openweathermapkey = "xxxxxxxxxxxxxxxx" # Enter your API Key here. You can get it from here - https://openweathermap.org/api
if city == "":
print("\nYou need to specify a location!")
time.sleep(5)
exit()
else:
city = city.lower()
city = city.replace(' ',',')
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/41.0.2228.0 Safari/537.36'}
api = f"http://api.openweathermap.org/data/2.5/weather?q={city}&units=metric&appid={openweathermapkey}"
r = requests.get(api, headers=headers)
response = r.json()
if response['cod'] == 200:

cityname = response['name']
country = response['sys']['country']
location = f"{cityname}, {country}"

cityid = response['id']
longitude = response['coord']['lon']
latitude = response['coord']['lat']

main = response['weather'][0]['main']
descriptiion = response['weather'][0]['description']
status = f"{main}({descriptiion})"

feels_likec = int(response['main']['feels_like'])
feels_likef = int((feels_likec * 1.8) + 32)

tempc = int(response['main']['temp'])
tempf = int((tempc * 1.8) + 32)

tempminc = int(response['main']['temp_min'])
tempminf = int((tempminc * 1.8) + 32)

tempmaxc = int(response['main']['temp_max'])
tempmaxf = int((tempmaxc * 1.8) + 32)

humidity = response['main']['humidity']

pressuret = response['main']['pressure']
pressurep = round(pressuret / 51.72, 2)

sunrise_raw = response['sys']['sunrise']
sunrise = time.strftime("%H:%M", time.gmtime(int(sunrise_raw)))

sunset_raw = response['sys']['sunset']
sunset = time.strftime("%H:%M", time.gmtime(int(sunset_raw)))

windk = int(response['wind']['speed'])
windm = int(windk * 0.62)


print(f"\n\n| Powered by openweathermap.org | ID: {cityid}\n\nLocation: {location}\nFeels like: {feels_likec}°C ({feels_likef}°F)\nTemperature: {tempc}°C ({tempf}°F)\nMin: {tempminc}°C ({tempminf}°F)\nMax: {tempmaxc}°C ({tempmaxf}°F)\nCoordinates: {longitude} , {latitude}\nStatus: {status}\nAir Pressure: {pressurep} psi\nHumidity: {humidity} vapour/m3\nWind Speed: {windk} km/h | {windm} m/s\nSunrise: {sunrise} GMT\nSunset: {sunset} GMT")
end = datetime.datetime.now()
total_time = (end - start).total_seconds()
print(f"\nDone!")

input(f"Total time taken : {total_time} seconds")
else:
print("\nNo data found")
time.sleep(3)
exit()

if __name__ == '__main__':
weather()