|
|
|
@ -1,14 +1,20 @@
|
|
|
|
|
import random
|
|
|
|
|
from typing import Optional
|
|
|
|
|
from typing import Callable, Optional
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def http_get(url: str) -> Optional[str]:
|
|
|
|
|
response = requests.get(url)
|
|
|
|
|
if response.status_code == 200:
|
|
|
|
|
return response.text
|
|
|
|
|
return None
|
|
|
|
|
def http_get(url: str, log_e: Optional[Callable] = None) -> Optional[str]:
|
|
|
|
|
"""Get the HTML as text from this URL.
|
|
|
|
|
log_e is an optional error logging function."""
|
|
|
|
|
try:
|
|
|
|
|
response = requests.get(url)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
except OSError as exc:
|
|
|
|
|
if log_e:
|
|
|
|
|
log_e(f"http_get error: {exc}")
|
|
|
|
|
return None
|
|
|
|
|
return response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def proc(proba_percentage: int) -> bool:
|
|
|
|
|