-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.py
More file actions
43 lines (36 loc) · 1.01 KB
/
run.py
File metadata and controls
43 lines (36 loc) · 1.01 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
import requests, sys
from string import ascii_lowercase
from random import choice
class Images:
def __init__(self, width, height):
self.width = width
self.height = height
self.url = f'https://picsum.photos/{width}/{height}'
def getImageURL(self):
imageURL = requests.get(self.url).url
return imageURL
def downloadImage(self):
text = ascii_lowercase
random_name = ''.join([choice(text) for x in range(10)])+'.jpg'
image = requests.get(self.url)
with open(random_name, 'wb') as f:
f.write(image.content)
f.close()
return random_name
def main():
width = str(input('Image Width: '))
height = str(input('Image Height: '))
print('[1] Get Image URL\n[2] Download Image')
option = str(input('Select Option: '))
start = Images(width,height)
if option == '1':
url = start.getImageURL()
print(f'[+] Image URL: {url}')
elif option == '2':
filename = start.downloadImage()
print(f'[+] Saved Image as {filename}')
else:
print('[-] Invalid Option.. ')
sys.exit()
if __name__ == '__main__':
main()