32 lines
764 B
Python
32 lines
764 B
Python
import random
|
|
from typing import 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 proc(proba_percentage: int) -> bool:
|
|
return random.random() < (proba_percentage / 100.0)
|
|
|
|
|
|
def limit_text_length(text, max_length=400):
|
|
"""Limit text size to 400 characters max."""
|
|
words = text.split(" ")
|
|
cut_text = ""
|
|
while words:
|
|
next_word = words.pop(0)
|
|
if len(cut_text) + len(next_word) + 1 >= max_length:
|
|
break
|
|
cut_text += next_word + " "
|
|
if len(cut_text) < len(text):
|
|
cut_text = cut_text[:-1] + "…"
|
|
else:
|
|
cut_text = cut_text.rstrip()
|
|
return cut_text
|