-
Notifications
You must be signed in to change notification settings - Fork 1
/
image-cmd.py
executable file
·28 lines (21 loc) · 1.09 KB
/
image-cmd.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
#!/usr/bin/env python3
# image-cmd scans web pages for images and displays them in a terminal
# web scraper command line tool with image viewer, time limited
# tool is called from the command line and does this:
#- get some list of image urls from the internet
#- picks a random image from list
#- displays that image to the terminal using shitty color terminal graphics
import os
import shutil
import random
import subprocess
# request url to scrape from user and assign it to a varible
url = input("Please enter a website to obtain images from:\n")
# call image-scraper and pass it the url, saving images in a new directory
subprocess.call(['/usr/bin/image-scraper','-s images','-m 10',url])
# randomly select a file within the images directory and assign its path to a variable
filePath = '/home/tony/image-cmd/ images/' + (random.choice(os.listdir('/home/tony/image-cmd/ images')))
# draw the image to the command line, using viu, passing it the path of the selected image
subprocess.call(['/usr/bin/viu', filePath])
# delete images directory
shutil.rmtree("images", ignore_errors=True, onerror=None)