Skip to content

Commit 6caaf93

Browse files
authored
API Project
Here, I am simply making a project API that fetches data from the API URL and fetches data. Made Small project using GUI.
1 parent 17afcea commit 6caaf93

File tree

8 files changed

+161
-0
lines changed

8 files changed

+161
-0
lines changed

API Project/date_time api.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import requests
2+
import datetime
3+
my_latitude = 20.593683
4+
my_longitude = 78.962883
5+
6+
parameters= {
7+
"lat":my_latitude,
8+
"lng":my_longitude,
9+
"formatted":0,
10+
"tzid":"Asia/Kolkata"
11+
}
12+
13+
response = requests.get("https://api.sunrise-sunset.org/json",params=parameters)
14+
response.raise_for_status()
15+
data=response.json()
16+
print(data["results"]["sunset"])
17+
a=datetime.datetime.now()
18+
print(a)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
import requests
3+
import smtplib
4+
from datetime import datetime
5+
6+
my_latitude=22.700720
7+
my_longitude=75.934700
8+
9+
10+
def iss_overhead():
11+
response = requests.get(url="http://api.open-notify.org/iss-now.json")
12+
data=response.json()
13+
current_latitude=float(data["iss_position"]["latitude"])
14+
current_longitude=float(data["iss_position"]["longitude"])
15+
16+
if my_longitude+5==current_longitude <=my_longitude-5 and my_latitude+5==current_latitude<=-5:
17+
return True
18+
19+
parameters = {
20+
"lat": MY_LAT,
21+
"lng": MY_LONG,
22+
"formatted": 0,
23+
}
24+
25+
response = requests.get("https://api.sunrise-sunset.org/json", params=parameters)
26+
response.raise_for_status()
27+
data = response.json()
28+
sunrise = int(data["results"]["sunrise"].split("T")[1].split(":")[0])
29+
sunset = int(data["results"]["sunset"].split("T")[1].split(":")[0])
30+
31+
time_now = datetime.now()
32+
33+
34+
my_email = "shubmrj@gmail.com"
35+
password = "vcwsqfzbmgjpgjkx"
36+
37+
with smtplib.SMTP("smtp.gmail.com", port=587) as connection:
38+
connection.starttls()
39+
connection.login(user=my_email, password=password)
40+
41+
connection.sendmail(
42+
from_addr=my_email,
43+
to_addrs="srnwda@gmail.com",
44+
msg="Subject:ISIS\n\n Hello , ISIS on your head. "
45+
)
46+
print("Successful Executed")
47+
48+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import requests
2+
from datetime import datetime
3+
4+
MY_LAT = 51.507351 # Your latitude
5+
MY_LONG = -0.127758 # Your longitude
6+
7+
response = requests.get(url="http://api.open-notify.org/iss-now.json")
8+
response.raise_for_status()
9+
data = response.json()
10+
11+
iss_latitude = float(data["iss_position"]["latitude"])
12+
iss_longitude = float(data["iss_position"]["longitude"])
13+
14+
#Your position is within +5 or -5 degrees of the ISS position.
15+
16+
17+
parameters = {
18+
"lat": MY_LAT,
19+
"lng": MY_LONG,
20+
"formatted": 0,
21+
}
22+
23+
response = requests.get("https://api.sunrise-sunset.org/json", params=parameters)
24+
response.raise_for_status()
25+
data = response.json()
26+
sunrise = int(data["results"]["sunrise"].split("T")[1].split(":")[0])
27+
sunset = int(data["results"]["sunset"].split("T")[1].split(":")[0])
28+
29+
time_now = datetime.now()
30+
31+
#If the ISS is close to my current position
32+
# and it is currently dark
33+
# Then send me an email to tell me to look up.
34+
# BONUS: run the code every 60 seconds.
35+
36+
37+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import requests
2+
3+
# from main import latitude
4+
5+
response = requests.get(url="http://api.open-notify.org/iss-now.json")
6+
7+
data=response.json()
8+
9+
current_latitude=data["iss_position"]["latitude"]
10+
current_longitude=data["iss_position"]["longitude"]
11+
22.8 KB
Loading
22.7 KB
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from tkinter import *
2+
import requests
3+
4+
def get_quote():
5+
response=requests.get("https://api.kanye.rest/")
6+
data = response.json()
7+
# print(response)
8+
# a=data["quote"]
9+
canvas.itemconfig(quote_text,text=data["quote"])
10+
11+
12+
13+
window = Tk()
14+
window.title("Kanye Says...")
15+
window.config(padx=50, pady=50)
16+
17+
canvas = Canvas(width=300, height=414)
18+
background_img = PhotoImage(file="background.png")
19+
canvas.create_image(150, 207, image=background_img)
20+
quote_text = canvas.create_text(150, 207, text="xyz", width=250, font=("Arial", 30, "bold"), fill="white")
21+
canvas.grid(row=0, column=0)
22+
canvas.itemconfig(quote_text,text=get_quote())
23+
24+
kanye_img = PhotoImage(file="kanye.png")
25+
kanye_button = Button(image=kanye_img, highlightthickness=0, command=get_quote)
26+
kanye_button.grid(row=1, column=0)
27+
28+
29+
30+
window.mainloop()

API Project/main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import requests
2+
3+
response=requests.get("http://api.open-notify.org/iss-now.json")
4+
5+
# if response.status_code==404:
6+
# raise Exception("That Resource Does not Exist.")
7+
# elif response.status_code==401:
8+
# raise Exception("You are not Authorize to access this data.")
9+
response.raise_for_status()
10+
11+
data= response.json()
12+
13+
longitude = data["iss_position"]["longitude"]
14+
latitude = data["iss_position"]["latitude"]
15+
iss_position =(longitude,latitude)
16+
17+
print(iss_position)

0 commit comments

Comments
 (0)