-
Notifications
You must be signed in to change notification settings - Fork 0
/
online_ops.py
94 lines (71 loc) · 2.45 KB
/
online_ops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import requests
import wikipedia
import pywhatkit as kit
from email.message import EmailMessage
import smtplib
from decouple import config
NEWS_API_KEY = config("NEWS_API_KEY")
OPENWEATHER_APP_ID = config("OPENWEATHER_APP_ID")
TMDB_API_KEY = config("TMDB_API_KEY")
EMAIL = config("EMAIL")
PASSWORD = config("PASSWORD")
def find_my_ip():
ip_address = requests.get('https://api64.ipify.org?format=json').json()
return ip_address["ip"]
def search_on_wikipedia(query):
results = wikipedia.summary(query, sentences=2)
return results
def play_on_youtube(video):
kit.playonyt(video)
def search_on_google(query):
kit.search(query)
def send_whatsapp_message(number, message):
kit.sendwhatmsg_instantly(f"+91{number}", message)
def send_email(receiver_address, subject, message):
try:
email = EmailMessage()
email['To'] = receiver_address
email["Subject"] = subject
email['From'] = EMAIL
email.set_content(message)
s = smtplib.SMTP("smtp.gmail.com", 587)
s.starttls()
s.login(EMAIL, PASSWORD)
s.send_message(email)
s.close()
return True
except Exception as e:
print(e)
return False
def get_latest_news():
news_headlines = []
res = requests.get(
f"https://newsapi.org/v2/top-headlines?country=in&apiKey={NEWS_API_KEY}&category=general").json()
articles = res["articles"]
for article in articles:
news_headlines.append(article["title"])
return news_headlines[:5]
def get_weather_report(city):
res = requests.get(
f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={OPENWEATHER_APP_ID}&units=metric").json()
weather = res["weather"][0]["main"]
temperature = res["main"]["temp"]
feels_like = res["main"]["feels_like"]
return weather, f"{temperature}℃", f"{feels_like}℃"
def get_trending_movies():
trending_movies = []
res = requests.get(
f"https://api.themoviedb.org/3/trending/movie/day?api_key={TMDB_API_KEY}").json()
results = res["results"]
for r in results:
trending_movies.append(r["original_title"])
return trending_movies[:5]
def get_random_joke():
headers = {
'Accept': 'application/json'
}
res = requests.get("https://icanhazdadjoke.com/", headers=headers).json()
return res["joke"]
def get_random_advice():
res = requests.get("https://api.adviceslip.com/advice").json()
return res['slip']['advice']