Repository navigation
Expand file tree
/
Copy pathmisc.py
More file actions
256 lines (210 loc) · 8.4 KB
/
Copy pathmisc.py
File metadata and controls
256 lines (210 loc) · 8.4 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import os
import re
import jikanpy
import requests
import wikipedia
from bs4 import BeautifulSoup
from textblob import TextBlob
SAFONE_API_URL = os.environ.get("SAFONE_API_URL", "https://api.safone.tech/")
async def wiki_search(query):
search_res = wikipedia.summary(query)
return search_res
async def xda_search(query):
srch_url = "https://www.xda-developers.com/search/" + query.replace(" ", "+")
ct = requests.get(srch_url)
search_res = ""
ml = BeautifulSoup(ct.content, "html.parser", from_encoding="utf-8")
ml = ml.find_all("div", re.compile("layout_post_"), id=re.compile("post-"))
for on in ml:
data = on.find_all("img", "xda_image")[0]
title = data["alt"]
thumb = data["src"]
hre = on.find_all("div", "item_content")[0].find("h4").find("a")["href"]
desc = on.find_all("div", "item_meta clearfix")[0].text
text = f"[{title}]({hre})"
search_res += (
f"Title:{title}\nDescription:{desc}\nURL:{hre}\nThumbnail:{thumb}\n{text}"
)
return search_res
async def youtube_search(query):
api_url = f"{SAFONE_API_URL}youtube"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def dictionary_search(query):
api_url = f"{SAFONE_API_URL}dictionary"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def google_search(query):
api_url = f"{SAFONE_API_URL}google"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def github_search(query):
api_url = f"{SAFONE_API_URL}github"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def image_search(query):
api_url = f"{SAFONE_API_URL}image"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def lyrics_search(query):
api_url = f"{SAFONE_API_URL}lyrics"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def npm_search(query):
srch_url = (
f"https://registry.npmjs.com/-/v1/search?text={query.replace(' ','+')}&size=7"
)
data = requests.get(srch_url)
search_res = ""
for obj in data["objects"]:
package = obj["package"]
url = package["links"]["npm"]
title = package["name"]
keys = package.get("keywords", [])
text = f"**[{title}]({package['links'].get('homepage', '')})\n{package['description']}**\n"
text2 = f"**Version:** `{package['version']}`\n"
text3 = f"**Keywords:** `{','.join(keys)}`"
search_res += (
f"Title:{title}\nURL:{url}\nKeywords:{keys}\n\n{text}{text2}{text3}"
)
return search_res
async def pypi_search(query):
api_url = f"{SAFONE_API_URL}pypi"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def reddit_search(query):
api_url = f"{SAFONE_API_URL}reddit"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def spellcheck(query):
res = TextBlob(query)
search_res = res.correct()
return search_res
async def tgsticker_search(query):
api_url = f"{SAFONE_API_URL}tgsticker"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def stackoverflow_search(query):
api_url = f"{SAFONE_API_URL}stackoverflow"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def torrent_search(query):
api_url = f"{SAFONE_API_URL}torrent"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def tmdb_search(query):
api_url = f"{SAFONE_API_URL}tmdb"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def urban_search(query):
api_url = f"{SAFONE_API_URL}urban"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def unsplash_search(query):
api_url = f"{SAFONE_API_URL}unsplash"
resp = requests.get(api_url, params={"query": query})
search_res = resp.text.strip()
return search_res
async def koo_search(query):
search_res = ""
se_ = None
key_count = None
query = query.replace(" ", "+")
srch_url = f"https://www.kooapp.com/apiV1/search?query={query}&searchType=EXPLORE"
req = requests.get(srch_url).json()
if key_count:
try:
se_ = [req["feed"][key_count - 1]]
except KeyError:
pass
if not se_:
se_ = req["feed"]
for count, feed in enumerate(se_[:10]):
if feed["uiItemType"] == "search_profile":
count += 1
item = feed["items"][0]
profileImage = (
item["profileImageBaseUrl"]
if item.get("profileImageBaseUrl")
else "https://telegra.ph/file/dc28e69bd7ea2c0f25329.jpg"
)
temp_url = "https://www.kooapp.com/apiV1/users/handle/" + item["userHandle"]
extra = requests.get(temp_url).json()
text = f"‣ **Name :** `{item['name']}`"
if extra.get("title"):
text += f"\n‣ **Title :** `{extra['title']}`"
text += f"\n‣ **Username :** `@{item['userHandle']}`"
if extra.get("description"):
text += f"\n‣ **Description :** `{extra['description']}`"
text += f"\n‣ **Followers :** `{extra['followerCount']}` ‣ **Following :** {extra['followingCount']}"
if extra.get("socialProfile") and extra["socialProfile"].get("website"):
text += f"\n‣ **Website :** {extra['socialProfile']['website']}"
desc = item.get("title") or f"@{item['userHandle']}"
search_res += f"Title:{item['name']}\nDescription:{desc}\nProfile Image:{profileImage}\n{text}"
return search_res
async def animechar_search(query):
jikan = jikanpy.jikan.Jikan()
try:
s = jikan.search("character", query)
except jikanpy.exceptions.APIException:
return "`Couldn't find character!`"
a = s["results"][0]["mal_id"]
char_json = jikan.character(a)
pic = char_json["image_url"]
msg = f"**[{char_json['name']}]({char_json['url']})\nImage:{pic}**"
if char_json["name_kanji"] != "Japanese":
msg += f" [{char_json['name_kanji']}]\n"
else:
msg += "\n"
if char_json["nicknames"]:
nicknames_string = ", ".join(char_json["nicknames"])
msg += f"\n**Nicknames** : `{nicknames_string}`\n"
about = char_json["about"].split("\n", 1)[0].strip().replace("\n", "")
msg += f"\n**About**: __{about}__"
return msg
async def winget_search(query):
search_res = ""
query = query.replace(" ", "+")
srch_url = f"https://api.winget.run/v2/packages?ensureContains=true&partialMatch=true&take=20&query={query}"
req = requests.get(srch_url).json()
for on in req["Packages"]:
data = on["Latest"]
name = data["Name"]
homep = data.get("Homepage")
text = f"> **{name}**\n - {data['Description']}\n\n`winget install {on['Id']}`\n\n**Version:** `{on['Versions'][0]}`\n"
text += "**Tags:**" + " ".join([f"#{_}" for _ in data["Tags"]])
if homep:
text += f"\n\n{homep}"
search_res += f"URL:{homep}\n{text}"
return search_res
async def omgubuntu_search(query):
search_res = ""
get_web = "https://www.omgubuntu.co.uk/?s=" + query.replace(" ", "+")
get_ = requests.get(get_web).content
BSC = BeautifulSoup(get_, "html.parser", from_encoding="utf-8")
for cont in BSC.find_all("div", "sbs-layout__item"):
img = cont.find("div", "sbs-layout__image")
url = img.find("a")["href"]
src = img.find("img")["src"]
con = cont.find("div", "sbs-layout__content")
tit = con.find("a", "layout__title-link")
title = tit.text.strip()
desc = con.find("p", "layout__description").text.strip()
text = f"[{title.strip()}]({url})\n\n{desc}"
search_res += (
f"Title:{title}\nImage:{src}\nDescription:{desc}\nURL:{url}\n{text}"
)
return search_res