-
Notifications
You must be signed in to change notification settings - Fork 9
/
addons.py
151 lines (136 loc) · 6.77 KB
/
addons.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import wikipedia
import urbandict
import requests
from urllib.parse import urlparse
from googletrans import Translator
from bs4 import BeautifulSoup
class Plugin:
def help(self):
return "/start - To check whether bot is online or not\n" \
"/help - Help message\n" \
"/tr <language code> = <text to translate>\n" \
"/dict <word> - English dictionary\n" \
"/maldict <word> - Eng-Mal dictionary\n" \
"/wiki <search query> - Wiki searching\n" \
"/mod <app name> - Get mod apps\n" \
"/klcovid - Kerala covid statistics\n" \
"/flip <product name> - Search flipkart products\n" \
"/weather <location> - weather\n" \
def parse_html(self, url):
return BeautifulSoup(requests.get(url).content,"html.parser")
def weather(self, location):
if not location:
return "format /weather kannur"
try:
api_url = f"https://api.openweathermap.org/data/2.5/weather?q={location.strip()}&units=metric&appid=1d74f5174b5bce8e43c9ac159905c7f6"
r = requests.get(api_url).json()
return f'*Location:* _{location.strip()}_\n' \
f'*Temperature:* _{r["main"]["temp"]}℃_\n' \
f'*Humidity:* _{r["main"]["humidity"]}_\n' \
f'*Wind Speed:* _{r["wind"]["speed"]}_\n' \
f'*Condition:* _{r["weather"][0]["description"]}_'
except:
return f"No results found for {location}"
def covid(self):
soup = self.parse_html("https://dashboard.kerala.gov.in/")
confirmed = soup.find("div",{"class":"small-box bg-info"}).h3.text
active = soup.find("div",{"class":"small-box bg-warning"}).h3.text
recovered = soup.find("div",{"class":"small-box bg-success"}).h3.text
death = soup.find("div",{"class":"small-box bg-danger"}).h3.text
updated = soup.find("li",{"class":"breadcrumb-item active"}).text
return f"🥺 *Confirmed:* {confirmed}\n\n😨 *Active:* {active}\n\n💚 *Recovered:* {recovered}\n\n😥 *Death:* {death}\n\n _{updated}_"
def flip(self, query):
if not query:
return "/flip <product name>"
soup = self.parse_html(f"https://www.flipkart.com/search?q={query.replace(' ','+')}")
parsed = soup.find_all("div",{"class":"_1-2Iqu row"})
if len(parsed) == 0:
return "No results"
msg = ""
for i,content in enumerate(parsed):
msg += f"*{content.find('div',class_='_3wU53n').get_text().strip()}*\n"
msg += "Price: " + content.find("div",class_="_1vC4OE _2rQ-NK").get_text() + "\n"
msg += content.find("span",class_="_38sUEc" ).get_text() + "\n" if content.find("span",class_="_38sUEc" ) else "No ratings\n"
msg += "".join([f"● _{specs.get_text().strip()}_\n" for specs in content.find_all("li",class_="tVe95H")])
prdct_url = "https://www.flipkart.com" + soup.find_all("div", {"class": "_1UoZlX"})[i].a.get('href')
msg += requests.get(f"https://da.gd/s?url={prdct_url}").text + "\n\n"
return msg
def dl_droid(self, app_name):
page = self.parse_html(f"https://dlandroid.com/?s={app_name.replace(' ','+')}")
results = page.find('div',class_="post")
if results:
page_url = results.find('a', href=True)['href']
app_id = urlparse(page_url).path.strip("/")
dwn_page = self.parse_html(f"https://dl-android.com/p/index.php?id={app_id}")
dwn_btn = dwn_page.find("div",class_="dlbtng")
link = ["*Available versions are:*\n\n"]
[link.append(links.get_text() + "\n" + links['href'] + "\n\n") for links in dwn_btn.find_all('a', href=True) if links.get_text() != "Azio - Download New Music Offline Free"]
return ''.join(link)
else:
return "No results found"
def mod(self, app_name):
if not app_name:
return "format\n/mod <app name>"
url = f"https://moddroid.com/?s={app_name.replace(' ','+')}"
page = self.parse_html(url)
content = page.find('div',{'class':'rd-details-top'})
if content:
app_url = content.find('a', href=True)['href']
dwn_page = self.parse_html(app_url + "?download")
app_urls = dwn_page.find('div',{'id':'download-tab'})
links = ["*Available versions are:*\n\n"]
[links.append(dwn_url.get_text() + "\n" + dwn_url['href'] + "\n\n") \
for dwn_url in app_urls.find_all('a', href=True)]
return ''.join(links)
else:
return self.dl_droid(app_name)
def translate(self, message):
try:
lan_code,text = message.split("=")
except:
return "```format /tr ml = Hello```\n" \
"_Language codes: https://developers.google.com/admin-sdk/directory/v1/languages_"
translator = Translator()
lan_code = lan_code.strip()
try:
translated = translator.translate(text.strip(), dest=lan_code)
return f"*Translated from {translated.src} to {lan_code}* \n_{translated.text}_"
except Exception as err:
return str(err)
def olam(self, query):
if not query:
return "No search query"
url = "https://olam.in/Dictionary/en_ml/{}".format(query.replace(" ", "+"))
page = self.parse_html(url)
content = page.find('div',{"id":"results"})
if content:
meaning = ""
for words in content.find_all('span'):
meaning += f"{words.text.strip()}\n"
return meaning
else:
return "No results found"
def udict(self, word):
try:
mean = urbandict.define(word)
return f"Word: {word}\n" \
f"Meaning: {mean[0]['def']}\n"
except:
return "No results found"
def wiki(self, query):
if not query:
return "Invalid search query"
try:
excerpt = wikipedia.summary(query)
except:
return "No results found"
return f"*Search query:* {query}\n" \
f"{excerpt.strip()}"
def msghandler(message): # Split commands and message text
msgs = message.split(' ',1)
return msgs if len(msgs) == 2 else [msgs[0].strip(),None]
def send_message(text=None):
if len(text) >= 65536:
text = "Exceeded character limit"
return {"replies": [{"message": text}]}
plugin = Plugin()