Use requests
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
requests>=2.31.0
|
||||||
|
|||||||
26
ytmnd.py
26
ytmnd.py
@@ -8,8 +8,8 @@ import time
|
|||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from urllib.request import urlopen, Request
|
import requests
|
||||||
from urllib.error import URLError, HTTPError
|
from requests.exceptions import RequestException
|
||||||
|
|
||||||
class YTMND:
|
class YTMND:
|
||||||
|
|
||||||
@@ -29,11 +29,11 @@ class YTMND:
|
|||||||
|
|
||||||
ytmnd_name = user
|
ytmnd_name = user
|
||||||
try:
|
try:
|
||||||
req = Request("http://ytmnd.com/users/" + ytmnd_name + "/sites",
|
response = requests.get("http://ytmnd.com/users/" + ytmnd_name + "/sites",
|
||||||
headers={'User-Agent': 'Mozilla/5.0'})
|
headers={'User-Agent': 'Mozilla/5.0'})
|
||||||
with urlopen(req) as response:
|
response.raise_for_status()
|
||||||
ytmnd_html = response.read().decode('utf-8').splitlines()
|
ytmnd_html = response.text.splitlines()
|
||||||
except (URLError, HTTPError) as e:
|
except RequestException as e:
|
||||||
print(f"Error fetching user page: {e}")
|
print(f"Error fetching user page: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -83,10 +83,10 @@ class YTMND:
|
|||||||
|
|
||||||
ytmnd_name = domain
|
ytmnd_name = domain
|
||||||
try:
|
try:
|
||||||
req = Request("http://" + domain + ".ytmnd.com",
|
response = requests.get("http://" + domain + ".ytmnd.com",
|
||||||
headers={'User-Agent': 'Mozilla/5.0'})
|
headers={'User-Agent': 'Mozilla/5.0'})
|
||||||
with urlopen(req) as response:
|
response.raise_for_status()
|
||||||
ytmnd_html = response.read().decode('utf-8')
|
ytmnd_html = response.text
|
||||||
|
|
||||||
expr = r"ytmnd.site_id = (\d+);"
|
expr = r"ytmnd.site_id = (\d+);"
|
||||||
match = re.search(expr, ytmnd_html)
|
match = re.search(expr, ytmnd_html)
|
||||||
@@ -95,12 +95,12 @@ class YTMND:
|
|||||||
return None
|
return None
|
||||||
ytmnd_id = match.group(1)
|
ytmnd_id = match.group(1)
|
||||||
|
|
||||||
req = Request("http://" + domain + ".ytmnd.com/info/" + ytmnd_id + "/json",
|
response = requests.get("http://" + domain + ".ytmnd.com/info/" + ytmnd_id + "/json",
|
||||||
headers={'User-Agent': 'Mozilla/5.0'})
|
headers={'User-Agent': 'Mozilla/5.0'})
|
||||||
with urlopen(req) as response:
|
response.raise_for_status()
|
||||||
ytmnd_info = json.load(response)
|
ytmnd_info = response.json()
|
||||||
|
|
||||||
except (URLError, HTTPError) as e:
|
except RequestException as e:
|
||||||
print(f"Error fetching {domain}: {e}")
|
print(f"Error fetching {domain}: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user