Skip to main content

A Cli tool for Grepsr Developers

Installation

$ pip install grepsr-cli

Usage

Using help

gcli --help

Using help for a specific command

gcli create --help

Tab completion

gcli generate tab-completion

Installs completion for bash, zsh or fish (detected from $SHELL, or pass --shell bash|zsh|fish). New shells pick it up automatically; to also turn it on in the shell you are in, do it in one step instead:

source <(gcli generate tab-completion --print)   # bash, zsh
gcli generate tab-completion --print | source    # fish

Completes subcommands, flag names, and crawler names read live from the paths in ~/.grepsr/config.yml — no need to re-run it when you clone a new crawler.

gcli crawler test -s amaz<TAB>            # every crawler starting with "amaz"
gcli crawler test -t node -s <TAB>        # only crawlers under node.paths

Creating crawler

gcli crawler create --init

This will take you to the interactive mode, where you can choose which crawler to create (PHP/JavaScript/Typescript)

Create crawler interactive mode

Running crawler.

gcli crawler test -s amazon_com

Running crawler with a parameter.

gcli crawler test -s amazon_com -p '{"urls":["https://amazon.com/VVUH4HJ","https://amazon.com/FV4434"]}'

if JSON is complex, use a file instead

# contents of /tmp/amazon_params.json
{"urls": ["https://amazon.com/VV%20UH4HJ"], "strip": ["'", "\"", "\\"]}

gcli crawler test -s amazon_com --params-file '/tmp/amazon_params.json'

Hacks Used.

If the json parameter has a space, it might break parameter parsing. If the json parameter has a dash - and any character after it has a space, it will break parameter parsing. Cause: no double quoting around $@ in run_service.php:5:49 here This is fixed hackily by replacing string with its unicode \u0020 sequence. This works beacause $@ does not split on \u0020.

Installing NodeJS package in a crawler

gcli crawler package-install -p @vortex-ts-sdk/http-crawler -t node -s grepsr_api_oxylab_com_report
gcli crawler package-install -p typescript -t node -s grepsr_api_oxylab_com_report

Updating a crawler's Vortex packages

Bumps every @vortex-ts-registry/* and @vortex-ts-sdk/* dependency to its latest version. Third party packages are left alone. You get an old → new preview to confirm first, and the crawler is compiled afterwards to check the new versions still build.

gcli crawler package-update -s grepsr_api_oxylab_com_report

Use --dry-run to see what would change without touching anything, -p to limit it to specific packages, and -y to skip the prompt.

gcli crawler package-update -s grepsr_api_oxylab_com_report --dry-run
gcli crawler package-update -s grepsr_api_oxylab_com_report -p @vortex-ts-sdk/http-crawler -y

gcli crawler test reminds you when a crawler has fallen behind:

WARNING: 3 vortex packages out of date:
         @vortex-ts-registry/crawler-utils   3.4.8 -> 5.3.9  (2 major versions)
         @vortex-ts-sdk/cache-handler        0.9.0 -> 0.13.1  (crosses 4 breaking 0.x releases)
         @vortex-ts-sdk/http-crawler        0.11.0 -> 0.14.1  (crosses 3 breaking 0.x releases)
       Run `gcli crawler package-update -s aakash_test_kathmandupost_com` to update.

It answers from a cache, so it costs a fraction of a millisecond and never delays the crawler. Once a day the run pauses up front to refresh that cache from the registry, and says so while it does. Running package-update refreshes it too, and CI never pauses for it.

Running Browser Automation

To run browser automation locally using gcli:

  1. Pull the browser image from AWS ECR:

    gcli browser pull <browser_name>
    
  2. Run the browser container:

    gcli browser run <browser_name>
    
  3. View the browser VNC stream using noVNC: To view the browser's graphical output, start the noVNC container mapping to the host's VNC port (5900):

    docker run \
      --add-host=host.docker.internal:host-gateway \
      -p 127.0.0.1:6080:6080 \
      gotget/novnc \
      --vnc host.docker.internal:5900
    

    Once running, open http://127.0.0.1:6080/vnc.html in your web browser to interact with the containerized browser.

inject custom command.

Say, for example, you wanted to inject a PHP function so that it could be called from inside your service code when testing locally. Note: All these files should only be created inside ~/.grepsr/tmp. Creating it outside will not work.

  1. Create a file called inject.php inside ~/.grepsr/tmp/
  2. Implement your function inside ~/.grepsr/tmp/inject.php
function addRowLocal($arr) {
    ...
    ...
}
  1. Create a file called inject.sh inside ~/.grepsr/tmp/
  2. inside inject.sh add:
alias php='php -d auto_prepend_file=/tmp/inject.php'

Note: the file location is /tmp/inject.php instead of ~/.grepsr/tmp/inject.php. This is because, the local path ~/.grepsr/tmp gets mapped to /tmp in the docker container. And inject.sh runs inside docker, instead of the local filesystem. 5. Add an entry in ~/.grepst/config.yml like so:

    php:
        ...
        sdk_image: ...
        pre_entry_run_file: inject.sh      # relative and limited to the tmp/ dir
  1. Now you can use addRowLocal() in your any of your files.
public function main($params) {
    ...
    $arr = $this->dataSet->getEmptyRow();
    addRowLocal($arr); // won't throw error
    ...
}

Would you like to contribute to grepsr-cli?

Be sure to uninstall gcli first, with pip uninstall grepsr-cli make changes, test and push.

git clone git@bitbucket.org:zznixt07/gcli.git grepsrcli
cd grepsrcli
pip install -e .

Features Added

  • drop stash after pushed successully. Before this, all stashes were always kept.
  • run a custom shell file before running your crawler. This allows possiblity like always injecting a php function in all your crawlers.
  • auto add Dependencies: ... that your crawler class extends (dependecies that are not extended by crawler classes but used elsewhere is upcoming)
  • Show modified files in the working tree that would be lost on git pull conflict, including the author name and date/time of the last local commit.
  • Scan PHP and Node (JS/TS) plugins for unexpected termination statements (e.g. die(), exit()) and merge conflict markers (<<<<<<< HEAD), prompting user before deployment.
  • Warn Node/TS crawler developers if src/ directory has changes but the compiled lib/ directory does not.
  • Expose CLI configuration globally so it can be read from anywhere, and print the docker run command when verbose mode is enabled.
  • Plugin names are checked for global uniqueness across every repo and language: create refuses a name that already exists anywhere, test/deploy warn when one resolves to more than one location.
  • On a duplicate plugin name, the copy closest to the current working directory is used instead of whichever repo happens to be configured first.

TODO:

  • Experiment with git rebase on deploy fail. git rebase origin/master --autostash && git push
  • Handle Prioritization of same plugin name across multiple repo more deterministically. (maybe prioritize cwd path?)
  • node only run crawler if npm install is successfull. (add && between npm install and npm start)
  • run tsc before deploying vortex-ts-registry packages
  • add option to force update dependecies to latest version for all/specific vortex-ts-registry dependencies
  • handle ctrl+c during node package install on docker. (currently it continues running in BG)
  • add new baseclass typescript package and do not include SOP, (do not normalize - to _) change npm start to tsc and test runs. Also generate .d.ts file in tsconfig.json

Metadata

Release files for grepsr-cli 0.10.31

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grepsr-cli 0.10.31
File Size Uploaded Provenance Actions
grepsr_cli-0.10.31.tar.gz 110.1 kB Without provenance Details for grepsr_cli-0.10.31.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for grepsr-cli 0.10.31
File Interpreter ABI Platform Actions
grepsr_cli-0.10.31-py3-none-any.whl Python 3 none any Details for grepsr_cli-0.10.31-py3-none-any.whl

Total release size: 205.3 kB

Release files / grepsr_cli-0.10.31.tar.gz

Download URL grepsr_cli-0.10.31.tar.gz
Size 110.1 kB
Tags Source
SHA-256 checksum
How to use checksums
00b9b898198421acf793c55a5425838888c63476fb40373dde27d774264c761b
BLAKE2b-256 checksum
How to use checksums
fa4464530d02bc8734db31712df223689cf37927773e183ef239a8d2a5daaff0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.4

Release files / grepsr_cli-0.10.31-py3-none-any.whl

Download URL grepsr_cli-0.10.31-py3-none-any.whl
Size 95.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08baf04ef5f1b383e0c9dd482829b7d01ecf95c157de729a62a2d9148b788fbb
BLAKE2b-256 checksum
How to use checksums
6ce1cede6e6f4af81f1907dd5e25987adf60f07edf4251847a1251500cd561d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.4

Security for grepsr-cli 0.10.31

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10.31 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page