diff --git a/README.md b/README.md index d834832..28619cd 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,10 @@ Complete mobile and desktop daily points using specified chrome profile "Profile `$ bing-rewards --profile "Profile 1"` +Run searches sequentially across multiple Chrome profiles + +`$ bing-rewards --profile "Default" "Profile 1" "Profile 2"` + Launches Chrome as a subprocess with special flags. Tested on Windows 10 and Linux (Ubuntu + Arch), however it should work on Mac OS as well. ⚠️Known Issue: No other instance of chrome.exe can be open when the script runs. Chrome prevents different user agents in each window. The script will run, but Chrome will not appear as Edge @@ -95,7 +99,7 @@ Options supplied at execution time override any config. | `--search-delay` | Override the time between searches in seconds | | `--exe EXE` | The full path of the Chrome compatible browser executable (Brave and Chrome tested) | | `--nowindow` | Don't open a new Chrome window, just type the keys | -| `--profile "Profile N"` | Launches chrome using the specified profile. Otherwise use default. | +| `--profile` | Run searches using specified Chrome profile(s). Multiple profiles can be specified to run sequentially | | `--ime` | Triggers Windows IME to switch to English input by pressing "shift" | A config file is also generated in $XDG_CONFIG_HOME or %APPDATA% on Windows diff --git a/bing_rewards/__init__.py b/bing_rewards/__init__.py index 5b5ef90..37d1fb0 100644 --- a/bing_rewards/__init__.py +++ b/bing_rewards/__init__.py @@ -225,55 +225,65 @@ def main(): Setup listener callback for ESC key. """ options = app_options.get_options() - words_gen = word_generator() - def desktop(): + def desktop(profile=''): # Complete search with desktop settings count = options.count if 'count' in options else options.desktop_count - print(f'Doing {count} desktop searches') + print(f'Doing {count} desktop searches using "{profile}"') - search(count, words_gen, options.desktop_agent, options) + temp_options = options + temp_options.profile = profile + search(count, words_gen, options.desktop_agent, temp_options) print('Desktop Search complete!\n') - def mobile(): + def mobile(profile=''): # Complete search with mobile settings count = options.count if 'count' in options else options.mobile_count - print(f'Doing {count} mobile searches') + print(f'Doing {count} mobile searches using "{profile}"') - search(count, words_gen, options.mobile_agent, options) + temp_options = options + temp_options.profile = profile + search(count, words_gen, options.mobile_agent, temp_options) print('Mobile Search complete!\n') - def both(): - desktop() - mobile() + def both(profile=''): + desktop(profile) + mobile(profile) # Execute main method in a separate thread if options.desktop: - target = desktop + target_func = desktop elif options.mobile: - target = mobile + target_func = mobile else: # If neither mode is specified, complete both modes - target = both - - # Start the searching in separate thread - search_thread = threading.Thread(target=target, daemon=True) - search_thread.start() - - print('Press ESC to quit searching') - - try: - # Listen for keyboard events and exit if ESC pressed - while search_thread.is_alive(): - with keyboard.Events() as events: - event = events.get(timeout=0.5) # block for 0.5 seconds - # Exit if ESC key pressed - if event and event.key == Key.esc: - print('ESC pressed, terminating') - break - except KeyboardInterrupt: - print('CTRL-C pressed, terminating') + target_func = both + + # Run for each specified profile (defaults to ['Default']) + for profile in options.profile: + # Start the searching in separate thread + search_thread = threading.Thread(target=target_func, args=(profile,), daemon=True) + search_thread.start() + + print('Press ESC to quit searching') + + try: + # Listen for keyboard events and exit if ESC pressed + while search_thread.is_alive(): + with keyboard.Events() as events: + event = events.get(timeout=0.5) # block for 0.5 seconds + # Exit if ESC key pressed + if event and event.key == Key.esc: + print('ESC pressed, terminating') + return # Exit the entire function if ESC is pressed + + except KeyboardInterrupt: + print('CTRL-C pressed, terminating') + return # Exit the entire function if CTRL-C is pressed + + # Wait for the current profile's searches to complete + search_thread.join() # Open rewards dashboard if options.open_rewards and not options.dryrun: diff --git a/bing_rewards/options.py b/bing_rewards/options.py index 00b927a..337fb0b 100644 --- a/bing_rewards/options.py +++ b/bing_rewards/options.py @@ -137,9 +137,10 @@ def parse_args() -> Namespace: ) p.add_argument( '--profile', - help='Sets the chrome profile for launch', + help='Sets one or more chrome profiles to run sequentially (space separated)', type=str, - default='', + nargs='+', + default=['Default'], ) p.add_argument( '--ime',