PandaAPI 1.0.0__tar.gz → 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PandaAPI
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Python utility hub by @ll_PANDA_BBY_ll
5
5
  Author: PANDA
6
6
  Author-email:
@@ -3,7 +3,6 @@ import string
3
3
  import re
4
4
  import requests
5
5
  from bs4 import BeautifulSoup
6
- from requests_html import HTMLSession
7
6
  from ..func import MORSE_CODE_DICT
8
7
 
9
8
 
@@ -142,26 +141,38 @@ def unsplash(query: str) -> dict:
142
141
 
143
142
  def imdb(query: str) -> dict:
144
143
  try:
145
- session = HTMLSession()
146
- r = session.get(f"https://www.imdb.com/find?q={query}")
147
- results = r.html.xpath(
148
- "//section[@data-testid='find-results-section-title']/div/ul/li"
149
- )
150
- if not results:
151
- return {"success": False, "error": "No results"}
152
- first_url = results[0].find("a")[0].attrs["href"]
153
- headers = {
154
- "User-Agent": (
155
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
156
- "AppleWebKit/537.36"
144
+ try:
145
+ from requests_html import HTMLSession
146
+ session = HTMLSession()
147
+ r = session.get(f"https://www.imdb.com/find?q={query}")
148
+ results = r.html.xpath(
149
+ "//section[@data-testid='find-results-section-title']/div/ul/li"
157
150
  )
158
- }
159
- page = requests.get(f"https://www.imdb.com/{first_url}", headers=headers)
151
+ if not results:
152
+ return {"success": False, "error": "No results"}
153
+ first_url = results[0].find("a")[0].attrs["href"]
154
+ except ImportError:
155
+ # fallback: plain requests + bs4
156
+ headers = {"User-Agent": "Mozilla/5.0"}
157
+ r = requests.get(
158
+ f"https://www.imdb.com/find?q={query}&s=tt", headers=headers
159
+ )
160
+ soup = BeautifulSoup(r.text, "html.parser")
161
+ result = soup.select_one(".ipc-metadata-list-summary-item a")
162
+ if not result:
163
+ return {"success": False, "error": "No results"}
164
+ first_url = result["href"]
165
+
166
+ headers = {"User-Agent": "Mozilla/5.0"}
167
+ page = requests.get(f"https://www.imdb.com{first_url}", headers=headers)
160
168
  soup = BeautifulSoup(page.text, "html.parser")
161
169
  import json as _json
162
- ld = _json.loads(soup.find("script", type="application/ld+json").string)
170
+ script = soup.find("script", type="application/ld+json")
171
+ if not script:
172
+ return {"success": False, "error": "Could not parse IMDB page"}
173
+ ld = _json.loads(script.string)
163
174
  return {
164
- "name": soup.title.text.strip(),
175
+ "name": soup.title.text.strip() if soup.title else "",
165
176
  "url": ld.get("url"),
166
177
  "image": ld.get("image"),
167
178
  "description": ld.get("description"),
@@ -233,7 +244,7 @@ def bhagwatgita(chapter: int, shalok: int = 1) -> dict:
233
244
  verses = soup.find_all("section", class_="listItem")
234
245
  texts = [
235
246
  v.text.strip()
236
- .replace("View commentary »", "")
247
+ .replace("View commentary \u00bb", "")
237
248
  .replace("Bhagavad Gita ", "")
238
249
  .strip()
239
250
  for v in verses
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PandaAPI
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Python utility hub by @ll_PANDA_BBY_ll
5
5
  Author: PANDA
6
6
  Author-email:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "PandaAPI"
7
- version = "1.0.0"
7
+ version = "1.0.1"
8
8
  authors = [
9
9
  { name = "PANDA" }
10
10
  ]
File without changes
File without changes
File without changes
File without changes
File without changes