-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightextender.py
More file actions
46 lines (42 loc) · 1.63 KB
/
lightextender.py
File metadata and controls
46 lines (42 loc) · 1.63 KB
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
import os.path
import urllib.request
from random import choice
from bs4 import BeautifulSoup
from requests import get
from os import system
class lightextender:
def generate(_symbols: str="qwertyuiopasdfghjklzxcvbnm1234567890", _len=6):
"""This function returns a random link index with a screenshot to lightshot"""
_index = ""
for i in range(0, _len):
_index += choice(_symbols)
return _index
def request(_index: str):
"""This function gets a link to the exact picture"""
opener = urllib.request.build_opener()
opener.addheaders = [('User-Agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)
html = urllib.request.urlopen("https://prnt.sc/"+_index).read()
soup = BeautifulSoup(html, 'html.parser')
try:
picture_url = soup.find(id='screenshot-image')['src']
except TypeError:
return False
return picture_url
def bashdownload(_source_url: str):
"""This function loads the image.
However, the download is done with
commands to terminal. Wget must already
be installed."""
if os.path.exists("images") != True:
system("mkdir images")
if _source_url != False:
return system("wget -P images/ -q "+ _source_url)
def download(_source_url: str):
"""This function downloads the picture using the urlretrieve"""
urllib.request.urlretrieve(_source_url, _source_url[32:])
def download_content(_source_url: str):
"""This function downloads the picture using the requests.get"""
if type(_source_url) not in [' ', bool]:
_output_url = _source_url.replace("https://i.imgur.com/", "").replace("https://image.prntscr.com/image/", "")
open(f"images/{_output_url}", "wb").write(get(_source_url).content)