@@ -28,8 +28,8 @@ def print_and_log(message, level=logging.INFO, sep=' ', end='\n', flush=False):
2828@click .option ('--ref-zones' , '-z' , default = ["gra" ,"rbx" ,"lon" ,"fra" ], show_default = True , multiple = True , help = 'Data center short name(s) (ie "-z gra -z rbx")' )
2929@click .option ('--quantity' , '-q' , default = 1 , show_default = True , help = 'Number of servers to rent - 1 to 5 (Maximum)' )
3030@click .option ('--payment-frequency' , '-f' , default = 1 , show_default = True , help = 'Receive the bill every 1,3,6 or 12 month' )
31- @click .option ('--ovh-user' , prompt = True , hide_input = False )
32- @click .option ('--ovh-pass' , prompt = True , hide_input = True )
31+ @click .option ('--ovh-user' , default = lambda : os . environ . get ( 'OVH_USERNAME' , '' ), show_default = 'OVH_USERNAME' , prompt = True , hide_input = False )
32+ @click .option ('--ovh-pass' , default = lambda : os . environ . get ( 'OVH_PASSWORD' , '' ), show_default = 'OVH_PASSWORD' , prompt = True , hide_input = True )
3333@click .option ('--debug/--no-debug' , default = False , help = 'Debug mode, disable by default. Add --debug flag to enable' )
3434def main (timeout_conn , interval , product_family , ref_product , ref_zones , quantity , payment_frequency , ovh_user , ovh_pass , debug ):
3535
@@ -42,7 +42,7 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
4242
4343 # define constants
4444 MAX_REQ_TIMEOUT_READ = 60
45- url_availability = "https://ws.ovh .com/dedicated/r2/ws.dispatcher/getAvailability2 "
45+ url_availability = "https://www.kimsufi .com/fr/js/dedicatedAvailability/availability-data-ca.json "
4646 not_available_terms = ['unknown' , 'unavailable' ]
4747
4848 script_dir = os .path .dirname (os .path .realpath (__file__ ))
@@ -51,14 +51,14 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
5151 screenshot_dir = os .path .join (os .getenv ("SCREENSHOT_DIR" , script_dir ), "screens" )
5252 if not os .path .exists (screenshot_dir ):
5353 os .makedirs (screenshot_dir )
54- print ("Saving screenshots in {}" .format (screenshot_dir ))
54+ print_and_log ("Saving screenshots in {}" .format (screenshot_dir ))
5555
5656 # Logs configuration
5757 log_dir = os .getenv ("LOG_DIR" , script_dir )
5858 if not os .path .exists (log_dir ):
5959 os .makedirs (log_dir )
6060 log_filename = os .path .join (log_dir , "buyKim.log" )
61- print ("Log filename: {}" .format (log_filename ))
61+ print_and_log ("Log filename: {}" .format (log_filename ))
6262 logging .basicConfig (format = '%(asctime)s - %(levelname)s - %(message)s' , filename = log_filename , level = logging .DEBUG )
6363 logging .getLogger ("requests" ).setLevel (logging .WARNING )
6464
@@ -74,9 +74,9 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
7474 request_ws = requests .get (url_availability , timeout = (timeout_conn , MAX_REQ_TIMEOUT_READ ))
7575 data = request_ws .json ()
7676
77- if 'answer' in data :
78- if 'availability' in data [ 'answer' ] :
79- available_servers = data ['answer' ][ ' availability' ]
77+ if data :
78+ if 'availability' in data :
79+ available_servers = data ['availability' ]
8080 found_product = False
8181 for line in available_servers :
8282 if line ['reference' ] == ref_product :
@@ -100,7 +100,6 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
100100 if available :
101101 break
102102
103- print_and_log ("None of the zones was available ({})" .format (", " .join (zone_avails )))
104103 if not found_zone :
105104 print_and_log ("None of the data center was found for product {}." .format (', ' .join (ref_zones ), ref_product ))
106105 if not found_product :
@@ -121,7 +120,7 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
121120 time .sleep (1 )
122121 msg_time = " (time: %f)" % time_elapsed
123122 if success :
124- print (msg_time )
123+ print_and_log (msg_time )
125124 logging .log (logging .DEBUG , log_msg + msg_time )
126125
127126 print_and_log ("Exited availability loop, {} is available in {}!" .format (ref_product , found_zone ))
@@ -157,6 +156,13 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
157156 driver .execute_script (js_select_dhs )
158157 print_and_log ("Selected {} datacenter." .format (found_zone ))
159158
159+ # pass cookie popup...
160+ try :
161+ driver .find_element_by_id ('header_tc_privacy_button' ).click ()
162+ print_and_log ("Passed the cookie popup window." .format (quantity ))
163+ except e :
164+ pass
165+
160166 # Select quantity and payment options
161167 selecor_quantity_line = driver .find_element_by_css_selector ('tbody.configuration tr:nth-child(2)' )
162168 selector_quantity = driver .find_element_by_css_selector ('tbody.configuration tr:nth-child(2) li:nth-child({})' .format (quantity ))
@@ -201,26 +207,31 @@ def main(timeout_conn, interval, product_family, ref_product, ref_zones, quantit
201207 screenshot_step (driver , screenshot_dir , 3 )
202208
203209 # Wait for means of payment to load
204- css_payment_valid = "div.payment-means-choice div.payment-means-list form span.selected input.custom-radio.ng-valid"
205- WebDriverWait (driver , 20 ).until (EC .presence_of_element_located (
206- (By .CSS_SELECTOR , css_payment_valid )
207- ))
210+ WebDriverWait (driver , 20 ).until (
211+ EC .element_to_be_clickable ((By .ID , "customConractAccepted" ))
212+ )
208213
209214 # Check inputs to accept contract conditions
210215 driver .find_element_by_id ("contracts-validation" ).click ()
211216 driver .find_element_by_id ("customConractAccepted" ).click ()
212217 print_and_log ("Checked confirmation inputs." )
218+ screenshot_step (driver , screenshot_dir , 4 )
219+
220+ selecor_payment_means = driver .find_element_by_css_selector ('div.payment-means form span span.first:nth-child(1) label' ).click ()
221+ print_and_log ("Checked confirmation inputs." )
222+ screenshot_step (driver , screenshot_dir , 5 )
213223
214224 # uncommented after numerous tests
215225 if not debug :
216226 css_button_purchase = "div.zone-content div.dedicated-contracts button.centered"
217227 driver .find_element_by_css_selector (css_button_purchase ).click ()
218228 print_and_log ("Clicked on purchase button..." )
229+ else :
230+ print_and_log ("Not clicking the purchase button because '--debug' flag was passed." )
219231
220232 # Wait to realise what you've done
221- screenshot_step (driver , screenshot_dir , 4 )
222- time .sleep (30 )
223- screenshot_step (driver , screenshot_dir , 5 )
233+ time .sleep (15 )
234+ screenshot_step (driver , screenshot_dir , 6 )
224235 driver .close ()
225236
226237
0 commit comments