@@ -6,6 +6,7 @@ import os
66import time
77
88from splinter import Browser
9+ from webdriver_manager .chrome import ChromeDriverManager
910
1011
1112def generate_config_file ():
@@ -30,7 +31,7 @@ def generate_config_file():
3031 with open ("watcard.json" , "w+" ) as json_file :
3132 json .dump (_config_info , json_file , indent = 2 )
3233 assert os .path .isfile ("watcard.json" ) is True
33- print ("Generate config file successfully. Please fill your information in watcard.json" )
34+ print ("[fund-my-watcard] Generate config file successfully. Please fill your information in watcard.json" )
3435
3536
3637class MyWatCard :
@@ -55,7 +56,7 @@ class MyWatCard:
5556
5657 def add_fund (self , amount ):
5758 try :
58- with Browser ("chrome" , ** {"executable_path" : os . environ [ "CHROMEDRIVER" ] }, incognito = True ,
59+ with Browser ("chrome" , ** {"executable_path" : ChromeDriverManager (). install () }, incognito = True ,
5960 headless = True ) as browser :
6061 browser .visit ("https://watcard.uwaterloo.ca/OneWebUW/addfunds_watiam.asp" )
6162 browser .fill ("UserName" , self .userName )
@@ -95,7 +96,7 @@ class MyWatCard:
9596class NoConfigFileException (Exception ):
9697 """Raised when watcard.json is not found."""
9798
98- def __init__ (self , message = "Cannot find watcard.json, run 'watcard --config' at first ." ):
99+ def __init__ (self , message = "[fund-my-watcard] Cannot find watcard.json, try 'watcard --config'." ):
99100 super (NoConfigFileException , self ).__init__ (message )
100101 self .message = message
101102
@@ -104,6 +105,7 @@ parser = argparse.ArgumentParser(description="Fund my WatCard: A tool to fund Wa
104105group = parser .add_mutually_exclusive_group ()
105106group .add_argument ("-c" , "--config" , help = "generate the config file" , action = "store_true" )
106107group .add_argument ("-f" , "--fund" , type = float , help = "the fund amount to the WatCard" , action = "store" )
108+ group .add_argument ("-v" , "--version" , help = "show the version of fund-my-watcard" , action = "store_true" )
107109args = parser .parse_args ()
108110
109111if args .config :
@@ -117,11 +119,14 @@ if args.fund:
117119 _my_wat_card = MyWatCard (** _config )
118120 res = _my_wat_card .add_fund (amount )
119121 if res :
120- print ("Adding ${} to account {} successfully." .format (amount , _config ["userName" ]))
122+ print ("[fund-my-watcard] Adding ${} to account {} successfully." .format (amount , _config ["userName" ]))
121123 else :
122- print ("Adding ${} to account {} failed." .format (amount , _config ["userName" ]))
124+ print ("[fund-my-watcard] Adding ${} to account {} failed." .format (amount , _config ["userName" ]))
123125 else :
124126 raise NoConfigFileException ()
125127
126- if not args .config and not args .fund :
127- args = parser .parse_args (["-h" ])
128+ if args .version :
129+ print ("fund-my-watcard v0.1.2" )
130+
131+ if not args .config and not args .fund and not args .version :
132+ parser .parse_args (["-h" ])
0 commit comments