-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
executable file
·65 lines (57 loc) · 1.66 KB
/
utils.py
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
import time
import urllib.request
import settings as s
import requests
tstring = "%Y-%m-%d %H:%M"
bees = "<script type='text/javascript' src='/bee.js'></script>"
def unix2hum(unix):
unix = int(unix)
return time.strftime(tstring, time.localtime(unix))
def lines(filen):
with open(filen, "r") as filen:
filen = filen.read().splitlines()
filen = [x for x in filen if len(x.strip())]
return len(filen)
def pclean(post):
post = post.split("<br>")
def wget(url, fn, w=1):
try:
page = urllib.request.urlopen(url)
page = page.read().decode('utf-8')
except:
page = ""
if ".onion" in url:
from requests_tor import RequestsTor
rt = RequestsTor(tor_ports=(s.torport,))
try:
page = rt.get(url).text
except Exception as e:
print(e)
page = ""
if "<!DOCTYPE" in page:
return ""
if not w:
return page
with open(fn, "w") as fn:
fn.write(page)
return page
def imgur(inp, host=s.ihost):
if not s.images:
return inp
img = inp.split(host)[1]
if " " or "<" in img:
term = len(img)
if 0 < img.find(" "):
term = img.find(" ")
if 0 < img.find("<") < term:
term = img.find("<")
img = img[:term]
if len(img) < 3:
return inp
if (3 < len(img) < 15) and ("." in img):
img = host + img
img2 = f"<a target='_blank' href='{img}'><img src='{img}'></a>"
# inp = inp.replace(img, " ", 1)
inp = "<p>".join([inp, img2])
return inp
#print(otnow, unix2hum(tnow))