Skip to content

Commit

Permalink
Merge pull request #37 from jack-mil/develop
Browse files Browse the repository at this point in the history
2.1.0 release staging
  • Loading branch information
jack-mil authored Aug 9, 2023
2 parents 62654c2 + 1b298f4 commit 274c4b4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 20 deletions.
55 changes: 41 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ If your chromium based browser has a different name use the `--exe` flag with an

## **Usage**

#### `bing-rewards [-h] [--no-window] [-n] [--exe EXE] [-c COUNT] [-d | -m]`
#### `bing-rewards [-h] [--no-window] [-n] [--exe EXE] [-c COUNT] [-d | -m] [--profile "Profile X"]`

Ex:
Complete mobile and desktop daily points
Expand All @@ -70,6 +70,10 @@ Run 10 searches with mobile user-agent in a new window

`$ bing-rewards --mobile --count=10`

Complete mobile and desktop daily points using specified chrome profile "Profile 1"

`$ bing-rewards --profile "Profile 1"`

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 @@ -80,19 +84,21 @@ Launches Chrome as a subprocess with special flags. Tested on Windows 10 and Lin
Running with no options will complete mobile and desktop daily search quota.
The following options are available to change the default behavior.
Options supplied at execution time override any config.
| Flag | Option |
| ----------------------- | ----------------------------------------------------------------------------------- |
| `-h`, `--help` | Display help and exit |
| `-c`, `--count=N` | Override the number of searches to complete (Desktop: 30, Mobile: 20) |
| `-d`, `--desktop` | Only use desktop user agent |
| `-m`, `--mobile` | Only use a mobile user agent |
| `-n`, `--dryrun` | Do everything but type the search query |
| `--open-rewards` | Open the rewards page at the end of the run |
| `-X`, `--no-exit` | Do not close the browser after completing a search |
| `--load-delay` | Override the time given to Chrome to load in seconds (1.5s) |
| `--search-delay` | Override the time between searches in seconds (2s) |
| `--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 |
| Flag | Option |
| ----------------------- | --------------------------------------------------------------------------------------|
| `-h`, `--help` | Display help and exit |
| `-c`, `--count=N` | Override the number of searches to complete |
| `-d`, `--desktop` | Only use desktop user agent |
| `-m`, `--mobile` | Only use a mobile user agent |
| `-n`, `--dryrun` | Do everything but type the search query |
| `--open-rewards` | Open the rewards page at the end of the run |
| `-X`, `--no-exit` | Do not close the browser after completing a search |
| `--load-delay` | Override the time given to Chrome to load in seconds |
| `--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. |
| `--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
where precise delay modifications can be made.
Expand Down Expand Up @@ -130,3 +136,24 @@ https://www.myhelpfulguides.com/2018/07/19/bing-rewards-auto-searcher-with-pytho

This script provided the original inspiration but has since been complelty rewritten and expanded.
The original author was contacted for the original source of keywords, but declined to respond

## Development

This project uses [Poetry](https://python-poetry.org) for dependency management and packaging.

The easiest way to install python apps is with [pipx](https://pypa.github.io/pipx/)

```
# Install pipx
pip install pipx
# Install poetry
pipx install poetry
```

Then, fork the repo, clone and install the dependencies with `poetry install`.

Install the defined pre-commit hooks: `poetry run pre-commit install`

Activate the virtualenv: `poetry shell`

Feel free to open a PR with additional features or fixes
37 changes: 32 additions & 5 deletions bing_rewards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ def parse_args():
help="Don't close the browser window after searching",
action="store_true",
)
p.add_argument(
"--profile",
help="Sets the chrome profile for launch",
type=str,
)
p.add_argument(
"--ime",
help="Triggers windows IME to switch to english by pressing SHIFT",
action="store_true",
)
return p.parse_args()


Expand Down Expand Up @@ -207,15 +217,20 @@ def check_python_version():
), "Only Python {}.{} and above is supported.".format(*minimum_version)


def browser_cmd(exe: Path | None, agent: str) -> List[str]:
def browser_cmd(exe: Path | None, agent: str, profile: str | None = None) -> List[str]:
"""
Generate command to open Google Chrome with user-agent `agent`
"""
if exe is not None:
browser = str(exe)
else:
browser = "chrome"
return [browser, "--new-window", f'--user-agent="{agent}"']
cmd = [browser, "--new-window", f'--user-agent="{agent}"']
# Switch to non default profile if supplied with valid string
# NO CHECKING IS DONE if the profile exists
if profile is not None:
cmd.extend(["--profile-directory=" + profile])
return cmd


def get_words_gen() -> Generator:
Expand Down Expand Up @@ -244,14 +259,22 @@ def search(count, words_gen: Generator, agent, args, config):
if not args.no_window and not args.dryrun:
if os.name == "posix":
chrome = subprocess.Popen(
browser_cmd(args.exe or config.get("browser-path") or None, agent),
browser_cmd(
args.exe or config.get("browser-path") or None,
agent,
args.profile,
),
stderr=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
preexec_fn=os.setsid,
)
else:
chrome = subprocess.Popen(
browser_cmd(args.exe or config.get("browser-path") or None, agent),
browser_cmd(
args.exe or config.get("browser-path") or None,
agent,
args.profile,
),
)
print(f"Opening browser with pid {chrome.pid}")
except FileNotFoundError as e:
Expand Down Expand Up @@ -282,6 +305,11 @@ def search(count, words_gen: Generator, agent, args, config):
key_controller.press("d")
key_controller.release("d")
key_controller.release(Key.alt)

if args.ime:
# Incase users use a Windows IME, change the language to English
# Issue #35
key_controller.tap(Key.shift)
time.sleep(0.08)

# Type the url into the address bar
Expand Down Expand Up @@ -318,7 +346,6 @@ def main():
# if args.dryrun:
# config["search-delay"] = 0
# config["load-delay"] = 0

words_gen = get_words_gen()

def desktop():
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bing-rewards"
version = "2.0.0"
version = "2.1.0"
description = "Perform automated Bing Rewards searches"
authors = ["jack-mil <62065280+jack-mil@users.noreply.github.com>"]
license = "MIT"
Expand Down

0 comments on commit 274c4b4

Please sign in to comment.