Skip to content

Commit

Permalink
Version 2.2.0 Release
Browse files Browse the repository at this point in the history
Version 2.2.0 Release
  • Loading branch information
jack-mil authored Nov 12, 2023
2 parents 274c4b4 + a883658 commit 16edf03
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 249 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pipx install bing-rewards

## **Requirements**

- At least Python 3.8
- At least Python 3.10

- [pynput](https://github.com/moses-palmer/pynput) package is used to control keypresses and type Bing search URLS.
WARNING: This script *will* take control away from the keyboard while running. **Pynput** performs key presses. i.e., it does not operate headless or in the background.
Expand Down Expand Up @@ -78,6 +78,8 @@ Launches Chrome as a subprocess with special flags. Tested on Windows 10 and Lin

⚠️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

⚠️Bing has gotten more and more complex with the introduction of the AI tools. Disable as much as you can to make pages load faster. See PR #39 for some modifications you can make to the default search query url parameters that may improve success.


## **Configuration**

Expand All @@ -101,7 +103,7 @@ Options supplied at execution time override any config.
| `--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.
where precise delay modifications can be made. If updates make changes to the default configs, you will have to remove and regenerate the file.

Example config `~/.config/bing-rewards/config.json`
```json
Expand All @@ -110,7 +112,7 @@ Example config `~/.config/bing-rewards/config.json`
"mobile-count": 20,
"load-delay": 1.5,
"search-delay": 2,
"search-url": "https://www.bing.com/search?q=",
"search-url": "https://www.bing.com/search?FORM=CHROMN&q=",
"desktop-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 Edg/83.0.478.37",
"mobile-agent": "Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Mobile Safari/537.36 Edge/18.19041",
"browser-path": "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
Expand Down
25 changes: 16 additions & 9 deletions bing_rewards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
$ bing-search -nmc30
$ bing-search --new --count=50 --mobile --dryrun
Config file generated in $XDG_CONFIG_HOME or %APPDATA% on Windows
where precise delay modifications can be made.
Config file generated at {CONFIG} where detailed settings can be configured
Command line arguments always override the config file.
Delay timings are in seconds.
"""

Expand Down Expand Up @@ -61,8 +61,8 @@
# Time between searches in seconds
SEARCH_DELAY = 2

# Bing Search base url
URL = "https://www.bing.com/search?q="
# Bing Search base url, with new form= parameter (code differs per browser?)
URL = "https://www.bing.com/search?form=QBRE&q="

# Reference Keywords from package files
KEYWORDS = Path(Path(__file__).parent, "data", "keywords.txt")
Expand All @@ -75,7 +75,7 @@
"search-url": URL,
"desktop-agent": DESKTOP_AGENT,
"mobile-agent": MOBILE_AGENT,
"browser-path": "",
"browser-path": "chrome",
}


Expand All @@ -100,6 +100,7 @@ def parse_args():
DESKTOP_COUNT=DESKTOP_COUNT,
MOBILE_COUNT=MOBILE_COUNT,
VERSION=get_version(),
CONFIG=get_config_file(),
),
epilog="* Repository and issues: https://github.com/jack-mil/bing-search",
formatter_class=argp.RawDescriptionHelpFormatter,
Expand Down Expand Up @@ -177,7 +178,7 @@ def parse_args():
return p.parse_args()


def parse_config(default_config: Dict) -> Dict:
def get_config_file() -> Path:
# Config file in .config or APPDATA on Windows
config_home = Path(
os.environ.get("APPDATA")
Expand All @@ -187,6 +188,11 @@ def parse_config(default_config: Dict) -> Dict:
)

config_file = config_home / "config.json"
return config_file


def parse_config(default_config: Dict) -> Dict:
config_file = get_config_file()

try:
# Read config from json dictionary
Expand All @@ -196,11 +202,12 @@ def parse_config(default_config: Dict) -> Dict:
except FileNotFoundError:
# Make directories and default config if it doesn't exist
print(f"Auto-Generating config at {str(config_file)}")
os.makedirs(config_home, exist_ok=True)
os.makedirs(config_file.parent, exist_ok=True)

with config_file.open("x") as f:
json.dump(default_config, f, indent=4)
return default_config

except JSONDecodeError as e:
print(e)
print("Error parsing JSON config. Please check your modifications.")
Expand All @@ -211,7 +218,7 @@ def check_python_version():
"""
Ensure the correct version of Python is being used.
"""
minimum_version = (3, 6)
minimum_version = (3, 10)
assert (
sys.version_info >= minimum_version
), "Only Python {}.{} and above is supported.".format(*minimum_version)
Expand Down Expand Up @@ -297,7 +304,7 @@ def search(count, words_gen: Generator, agent, args, config):
query = next(words_gen)

# Concatenate url with correct url escape characters
search_url = URL + quote_plus(query)
search_url = (config.get("search-url") or URL) + quote_plus(query)
# Use pynput to trigger keyboard events and type search querys
if not args.dryrun:
# Alt + D to focus the address bar in most browsers
Expand Down
Loading

0 comments on commit 16edf03

Please sign in to comment.