-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
157 lines (121 loc) · 4.07 KB
/
run.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"""
------------------------------------------------------------------------
File to launch Switch Snatcher
------------------------------------------------------------------------
File: run.py
Author: bb $kreetz
Email: [email protected]
__updated__ = "2020-04-12"
------------------------------------------------------------------------
"""
from SETTINGS import *
from CONSTANTS import *
from SwitchSnatcher import *
import colorama
import time
running = True
colorama.init()
def clear():
print("\x1b[2J")
def reposition(x, y):
print("\x1b[{};{}H".format(x + 1, y + 1))
def reset_screen():
clear()
reposition(0, 0)
print(colorama.Fore.YELLOW + INTRO + colorama.Fore.RESET)
while running:
reset_screen()
print('1) Start Checking Websites')
print('2) Add New Websites')
print('3) Remove Websites')
print('4) Exit Program')
x = input('--> ')
if x == '1':
x = None
try:
start_checking()
except Exception as e:
print(f'Error: {e}')
time.sleep(5)
elif x == '2':
x = None
adding_site = True
site_type = None
while adding_site:
reset_screen()
# print('Supported Websites:', ', '.join(map(str, SITE_TYPES)))
print('Supported Websites: amazon')
url = input('URL: ')
if 'amazon.ca' in url.lower():
site_type = 'amazon'
elif 'bestbuy.ca' in url.lower():
site_type = 'bestbuy'
elif 'thesource.ca' in url.lower():
site_type = 'thesource'
elif 'walmart.ca' in url.lower():
site_type = 'walmart'
elif 'staples.ca' in url.lower():
site_type = 'staples'
elif 'ebgames.ca' in url.lower():
site_type = 'ebgames'
if site_type is not None:
max_price = None
while type(max_price) is not float:
reset_screen()
max_price = input('Maximum price to pay: ')
try:
max_price = float(max_price)
reset_screen()
print('Adding website...')
added = add_website(url, site_type, max_price)
if added:
print('Done!')
else:
print('Website already exists.')
adding_site = False
time.sleep(2)
except Exception as e:
print(e)
print('Please enter a valid price.')
time.sleep(2)
else:
reset_screen()
print('Please check the URL and make sure it is valid.')
time.sleep(2)
elif x == '3':
x = None
removing = True
while removing:
items = {}
count = 0
reset_screen()
for i in URL_MAP:
count += 1
items[count] = i
print(f'{count}) {URL_MAP[i]}')
try:
print("\nenter 'x' to go back.")
to_remove = input('Website to remove: ')
reset_screen()
if to_remove.lower() == 'x':
removing = False
elif int(to_remove) in items:
if remove_website(items[int(to_remove)]):
print('Successfully removed.')
removing = False
else:
print('Error, please try again.')
time.sleep(2)
else:
print('Please enter a valid number.')
time.sleep(2)
except ValueError:
print('Please enter a valid number.')
time.sleep(2)
elif x == '4':
clear()
running = False
else:
reset_screen()
print('Invalid selection...')
time.sleep(2)