Add new limit option to limit the requested amount of posts from the Reddit API #203

Merged
Vylpes merged 3 commits from feature/137-limit-option into develop 2024-07-26 18:23:19 +01:00
2 changed files with 29 additions and 12 deletions
Showing only changes of commit 657bc7df59 - Show all commits

View file

@ -4,7 +4,7 @@ Since Version 2.2, Random Bunny contains a command line interface (CLI).
## Downloads
The project can be downloaded as a binary for your system via the [GitHub Releases](https://github.com/Vylpes/random-bunny/releases) or [Gitea Releases](https://gitea.vylpes.xyz/RabbitLabs/random-bunny/releases) page.
The project can be downloaded as a binary for your system via the [GitHub Releases](https://github.com/Vylpes/random-bunny/releases) or [Forgejo Releases](https://git.vylpes.xyz/RabbitLabs/random-bunny/releases) page.
We currently support:
- Linux (x64)
@ -13,6 +13,8 @@ We currently support:
The git repository can also be cloned and ran via `yarn build` and `yarn start`.
You can produce the binary using the `yarn package` command. This creates the binaries in the `./bin` folder.
> **NOTE:** We are aware of a bug in the macOS Arm64 builds failing to execute. For now you're still able to use the x64 builds under Rosetta fine. This will hopefully be fixed in a future release.
## Default Output
@ -20,7 +22,7 @@ The git repository can also be cloned and ran via `yarn build` and `yarn start`.
By default, the command will fetch a random image from `r/rabbits` and return it in a human-readable output.
```
$ randombunny
$ random-bunny
Archived = false
Downvotes = 0
@ -38,11 +40,11 @@ Url = https://i.redd.it/sfz0srdrimjc1.png
The command also includes a help option in case you are stuck.
```
$ randombunny --help
$ random-bunny --help
# or
$ randombunny -h
$ random-bunny -h
Usage: random-bunny [options]
@ -55,6 +57,7 @@ Options:
-q, --query-metadata Include query metadata in result
-o <file> Output to file
--sort <sort> Sort by (choices: "hot", "new", "top", default: "hot")
--limit <limit> The amount of posts to fetch from the reddit api (default: 100)
-h, --help display help for command
```
@ -63,11 +66,11 @@ Options:
You can also convert the output into JSON, if you need to input it to another program.
```bash
$ randombunny --json
$ random-bunny --json
# or
$ randonbunny -j
$ randon-bunny -j
{"Archived":false,"Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1av1rg9/cute_baby_bun/","Subreddit":"Rabbits","SubredditSubscribers":486085,"Title":"Cute baby bun","Ups":210,"Url":"https://i.redd.it/sfz0srdrimjc1.png"}
```
@ -79,9 +82,9 @@ You can also choose the sorting option which reddit will use to return the avail
This defaults to "hot". The valid options are "hot", "new", and "top".
```
$ randombunny --sort hot
$ randombunny --sort new
$ randomBunny --sort top
$ random-bunny --sort hot
$ random-bunny --sort new
$ random-bunny --sort top
```
@ -92,8 +95,8 @@ You can change the subreddit which the command fetches from.
This defaults to "rabbits"
```
$ randombunny --subreddit rabbits
$ randombunny -s horses
$ random-bunny --subreddit rabbits
$ random-bunny -s horses
```
## Output to file
@ -103,3 +106,17 @@ If you'd rather send the output to a file, you can supply the `-o` flag.
```
$ randombunny -o ~/Desktop/output.txt
```
## Reddit API Return Limits
You can also limit the amount the posts the script requests from the Reddit API
using the `--limit` option.
This defaults to 100. This accepts any number between 1 and 100.
Please note limiting the calls to less than 100 will give a higher chance of
the script not finding any valid image post to return.
```
$ random-bunny --limit 50
```

View file

@ -33,7 +33,7 @@ console.log(result);
### `randomBunny()`
Returns a `json string` for a random post. Accepts 2 arguments: `subreddit`, and `sortby` ('new', 'hot', 'top')
Returns a `json string` for a random post. Accepts 3 arguments: `subreddit`, `sortby` ('new', 'hot', 'top'), and `limit` (1-100, default 100)
The json string which gets returned consists of:
- archived