dwm/dwmscripts/scrot.py

75 lines
1.8 KiB
Python
Raw Normal View History

2023-11-01 04:52:21 +03:00
import os
from random import choice
# from requests import get
INDEX_HTML = "/home/naki/server/index.html"
SERVER_PATH = "/home/naki/server/a/"
LULS_PATH = "/home/naki/server/luls/"
RANDOM_SIZE = 5
RANDOM_ALPHABET = (
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789"
)
def gen_random(size, alphabet) -> str:
out = ''
for _ in range(size):
out += choice(alphabet)
return out
def main() -> None:
images = next(os.walk(SERVER_PATH), (None, None, []))[2]
# images = list(map(int, [image[3:-4] for image in images]))
images = [image[:-4] for image in images]
# out = max(images) + 1 if images else 0
name = ''
while True:
name = gen_random(RANDOM_SIZE, RANDOM_ALPHABET)
if name not in images:
break
os.system(f"/home/naki/dwmscripts/scrotpy.sh '{SERVER_PATH + name + '.png'}'")
# os.system(
# f"flameshot gui --raw > {SERVER_PATH}img{out}.png"
# )
# os.system(
# f"flameshot gui --raw > {SERVER_PATH}{name}.png"
# )
ip = "nakidai.ddns.net" # get('https://api.ipify.org').content.decode('utf8')
os.system(
f"echo \"http://{ip}/a/{name}.png\" |"
f" xclip -selection clipboard -r"
)
with open(INDEX_HTML, 'w') as f:
f.write(f"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nakidai Perumenei</title>
</head>
<body>
<h6>Latest screenshot:<h6>
<tt>
https://{ip}/a/{name}.png
</tt>
<h6>Cool things:<h6>
<code>
{"<br>".join([f"https://{ip}/luls/{img}<br>"
for img in os.listdir(LULS_PATH)])}
</code>
</body>
</html>""")
if __name__ == '__main__':
main()