Skip to content

Commit

Permalink
feat: support multiple Chrome profiles for sequential runs (#55)
Browse files Browse the repository at this point in the history
This PR enhances the --profile argument to support running searches across multiple Chrome profiles sequentially.
Changes:

    Modified --profile argument to accept zero or more profile names
    Added profile-specific messaging in console output
    Updated README with the said changes

Example usage:

bing-rewards --profile Default 'Profile 1' 'Profile 2'
  • Loading branch information
znarfm authored Feb 10, 2025
1 parent 678f98e commit bba536e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
72 changes: 41 additions & 31 deletions bing_rewards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions bing_rewards/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit bba536e

Please sign in to comment.