-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.py
96 lines (81 loc) · 2.35 KB
/
view.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import subprocess
import sys
import time
from core.banner import banner
from core.scrape import *
# Define colors
red = "\033[91m"
green = "\033[92m"
reset = "\033[0m"
def main():
# Clear up the terminal screen
subprocess.call("clear", shell=True)
print(banner())
print()
# Check the validity of user entered subreddit and assign its value to sub
sub = check_validity()
# Category menu
print ("""%s[+] Wubba Lubba dub-dub!
Select a Category:
1) Top
2) New
3) Hot
4) Rising
5) Exit
"""%(green))
# Loop until valid category is selected
while(True):
ch = int(input("%sEnter your choice: %s"%(green, reset)))
print()
if ch==1 or ch==2 or ch==3 or ch==4 or ch==5:
if ch==5:
sys.exit()
else:
break
else:
print("%s[-] Invalid input detected please enter a valid input!"%(red))
print()
# Fetch the image url based on the user set parameters and display them
if ch==1:
print("%s[+] Fetching the top images from r/{}....".format(sub)%(green))
print()
time.sleep(1)
result = get_img(sub, "top")
# Used an if else in all cases to check whether result is false or has the list
if not result:
sys.exit(1)
else:
display(result)
elif ch==2:
print("%s[+] Fetching the new images from r/{}....".format(sub)%(green))
print()
time.sleep(1)
result = get_img(sub, "new")
if not result:
sys.exit(1)
else:
display(result)
elif ch==3:
print("%s[+] Fetching the hot images from r/{}....".format(sub)%(green))
print()
time.sleep(1)
result = get_img(sub, "hot")
if not result:
sys.exit(1)
else:
display(result)
elif ch==4:
print("%s[+] Fetching the rising images from r/{}....".format(sub)%(green))
print()
time.sleep(1)
result = get_img(sub, "rising")
if not result:
sys.exit(1)
else:
display(result)
if __name__=="__main__":
try:
main()
except KeyboardInterrupt:
print("\n%s[-] SIGTERM recievied terminating...%s"%(red,reset))
sys.exit(1)