GithubHelp home page GithubHelp logo

melvio / hopla Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 7.0 754 KB

A Python CLI for habitica.com

License: Apache License 2.0

Shell 1.03% Makefile 0.38% Python 98.58%
cli habitica python3 python-click python-requests todo productivity commandline bash task-management

hopla's Introduction

๐Ÿฉบ ๐Ÿ“– ๐Ÿ‹๏ธ ๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿง‘โ€โš•๏ธ โš•๏ธ ๐Ÿฉบ ๐Ÿ“– ๐Ÿ‹๏ธ ๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿง‘โ€โš•๏ธ โš•๏ธ ๐Ÿฉบ ๐Ÿ“– ๐Ÿ‹๏ธ ๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿง‘โ€โš•๏ธ โš•๏ธ ๐Ÿฉบ ๐Ÿ“– ๐Ÿ‹๏ธ ๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿง‘โ€โš•๏ธ โš•๏ธ ๐Ÿฉบ ๐Ÿ“– ๐Ÿ‹๏ธ ๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿง‘โ€โš•๏ธ โš•๏ธ ๐Ÿฉบ ๐Ÿ“– ๐Ÿ‹๏ธ ๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿง‘โ€โš•๏ธ โš•๏ธ ๐Ÿฉบ ๐Ÿ“– ๐Ÿ‹๏ธ ๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿง‘โ€โš•๏ธ โš•๏ธ ๐Ÿฉบ ๐Ÿ“– ๐Ÿ‹๏ธ

Software Developer & Medical Student.

hopla's People

Contributors

cubical8569 avatar guri-x avatar melvio avatar rickie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hopla's Issues

Increase linter grade to 10.0

Currently, only the following lint errors exists:

$ pylint $(find src/ -name "*.py") --rcfile=./.github/workflows/pylintrc.conf
************* Module hopla.cli.config
src/hopla/cli/config.py:54:1: W0511: TODO: get_user this value from the HoplaDefaultConfiguration class instead of duplicating it here (fixme)
************* Module hopla.cli.get_user.auth
src/hopla/cli/get_user/auth.py:25:1: W0511: TODO: probably better to remove profilename here regardless (fixme)
************* Module hopla.hoplalib.configuration
src/hopla/hoplalib/configuration.py:108:5: W0511: TODO: this would be nicely testable (fixme)
************* Module hopla.hoplalib.authorization
src/hopla/hoplalib/authorization.py:165:13: W0511: TODO: handle this better: (fixme)

These are all relatively low prio (fixme) errors.

Proposed solution:

  • Instead of using the code as issue tracker, put these issues on github instead.
  • Bump the minimal linting score to 10.0
  • Change the Makefile to turn make test from && to ; make lint ; make unittest
    • That way, locally, you can run tests while violating the linter for a few minutes.

Improve repo for healthy contributions

Go to the list over here and improve the repository:

  • [] About community management and moderation
  • [] About community profiles for public repositories
  • [] Accessing a project's community profile
  • [] Adding a code of conduct to your project
  • Setting guidelines for repository contributors: #110
  • Adding a license to a repository
  • [] Adding support resources to your project
  • [] Creating a default community health file
  • Encouraging helpful contributions to your project with labels: First ticket with 'good-first-issue' label: #105

Add --feed-until-out-of-food option

hopla feed --feed-until-out-of-food feeds all unfed pets with their favorite food.

Algorithm:

food_stockpile = get_available_food()
requests = []
requests, food_stockpile = calc_how_many_1favorite_food_pets_can_be_fed_as_possible(food_stockpile)
requests, food_stockpile = calc_how_many_magic_hatchingpotion_pets_can_be_fed_as_possible(food_stockpile)
print(<per pet to be fed: what food, how many times>)
print(<total food to be used>)
print(<total food remaining>)

ask_for_confirmation()
Y[es] -> execute feeding
else   -> exit with 0

Create hopla get-user profile

TODO comment from #107

# username -> 'data.auth.local.username':
# * Your username is used for invitations, @mentions in chat, and messaging.
#   * It:
#     + must be 1 to 20 characters,
#     + must contain only letters a to z, numbers 0 to 9, hyphens, or underscores, and
#     + cannot include any inappropriate terms.
# * is changeable at '<https://habitica.com/user/settings/site>' 'Change Display Name'

# profilename -> 'data.profile.name'
# *  is changeable at '<https://habitica.com/user/settings/site>' under 'Change Display Name'
# profilename is not really in the .data.auth section of /user.. but fits well here
# TODO: probably better to remove profilename here regardless

Add hopla cast command

Initial logic:

hopla cast {spell}

This ticket will support all spells that are casted on the party/user.
{spell} should be autocompletable
Aliases if the UI doesn't correspond with naming should make this even easier, but this is out of scope.
Casting on specific tasks is also out of scope.
Future command that are out of scope for now:

hopla cast {spell} [target]
hopla cast {spell} [target] --until-mana-left {N}
hopla cast {spell} [target] --until-no-mana-left

Refactor hopla config

Currently, way too much code is used for something simple.
This has to do with the migration from bash.
Now we use a different config file format, for which python has a lot of support. Use that instead.

Marked it low-prio. It works as intended. And it nicely separated from the rest of the code base.
Mostly it is in configuration.py

Implement throttling for feed-all for long feeding lists

If users have long list of unfed pets and lots of food hopla should be able to feed all of them.
Currently, hopla will simply timeout after 28-29 pets or so.

Current workaround: run hopla feed-all until it halts and fails. Retry after 60s to feed the next batch.

Proposed solution:
Reuse the logic from hopla buy enchanted-armoire.
The buy command will check how many API requests are needed.
If this number is high, throttle by only executing 1 request per 2.5s.

Add hopla buy enchanted-armoire dryrun option for --times and --until-poor

E.g.:

$ hopla buy enchanted-armoire --until-poor -n
$ hopla buy enchanted-armoire --until-poor --dry-run 
You have n*100 gp, without -n this would buy n times

$ hopla buy enchanted-armoire --times N -n
$ hopla buy enchanted-armoire --times N --dry-run 
You have n*100gp, thus buying N times (when possible)
You have n*100gp, thus buying M times (where M < N, when cannot afford to buy N times)

Add get-group command

spec:

hopla get-group # gets party info
hopla get-group party # also get party
hopla get-group habitrpg # get tavern
hopla get-group {uuid}  # get group/guild information by uuid

Setting an invalid config values disallows setting a correct one

Bug:

$ hopla config cmd_all.loglevel debu
cmd_all.loglevel=debu

$ hopla config cmd_all.loglevel debug
hopla config cmd_all.loglevel debug
Traceback (most recent call last):
  File "/home/m/Documents/lcl/melvio/hopla/venv/bin/hopla", line 33, in <module>
    sys.exit(load_entry_point('hopla', 'console_scripts', 'hopla')())
  File "/home/m/Documents/lcl/melvio/hopla/venv/bin/hopla", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/m/Documents/lcl/melvio/hopla/src/hopla/__init__.py", line 50, in <module>
    log = setup_logging()
  File "/home/m/Documents/lcl/melvio/hopla/src/hopla/__init__.py", line 44, in setup_logging
    level=loglevel_mapping[parsed_loglevel],
KeyError: 'debu'

Version: commit: 84f31b3

Proposed solution: Input validation when setting config vargs.

hopla request can only accept strings as body params

The following command fails:

hopla request -XPOST --body-param uuids [wikiFAQ_bot] /api/v3/groups/party/invite

With:
HTTP Status Code: 400

{
    "success": false,
    "error": "BadRequest",
    "message": "User ID invites must be an array."
}

This is because the --body-parameter option only accepts strings at the moment.

Implement hopla feed-all {gen1pets|quest-pets|magic-pets}

Currently, we only have the following command that feeds all pets:

hopla feed-all

This ticket would implement:

hopla feed-all gen1pets
hopla feed-all quest-pets
hopla feed-all magic-pets

These commands will only feed one of the corresponding types of pets.

Implementing this wouldn't be too hard, since much of the functionality is already in place in the hoplalib.zoo package.

I labelled this ticket with low-priority because I don't have any need for this.
However, if there is a lot of animo for hopla and this functionality (let's say 10 github stars and 3 requests on this ticket), I can implement it for the community.

Reminder: Improve documentation

This is a generic issue to go over the documentation once in a while just to make sure it is still up to date with the code.

Documentation of interest:

  • CLI output documentation
  • CONTRIBUTING.md
  • README.md
  • code documentation
  • hopla wiki

Lint testing code

We should also lint testing code with a config that is similar to the normal code.
However, the config should not be the same: e.g.

  • line length can be a bit more (e.g. 120) and
  • not every function needs documentation.

Environment Variables for Hopla's options

Hopla should provide the following:

Environment Variables for Hopla's options

Use case: You can use environment variables to set default values for all Hopla options.

Hopla automatically recognizes environment variables starting with HOPLA_. All option (such
as --difficulty for hopla add todo and --amount for hopla feed) can be set in this manner.

To get the right environment variable name, use this logic:

  1. Define an environment variable starting with HOPLA_
  2. Append the subcommand to the environment variable as follows:
    • hopla add todo -> HOPLA_ADD_TODO_
    • hopla support-development -> HOPLA_SUPPORT_DEVELOPMENT_
    • hopla feed -> HOPLA_FEED_
  3. Append the option name that you want to set as follows:
    • hopla add todo --difficulty -> HOPLA_ADD_TODO_DIFFICULTY
    • hopla support-development --gems -> HOPLA_SUPPORT_DEVELOPMENT_GEMS
    • hopla feed --amount -> HOPLA_FEED_AMOUNT

For example:

HOPLA_ADD_TODO_DIFFICULTY=hard    hopla add todo "Hello"
HOPLA_SUPPORT_DEVELOPMENT_GEMS=8  hopla support-development
HOPLA_FEED_AMOUNT=3               hopla feed Wolf-Shade Chocolate

Other examples:

# add a To-Do for today
HOPLA_ADD_TODO_DUE_DATE=today hopla add todo "Task with Deadline from today"

# automatically enable autocomplete for bash 
HOPLA_COMPLETE_ENABLE=true    hopla complete bash
HOPLA_COMPLETE_ENABLE=yes     hopla complete bash
HOPLA_COMPLETE_ENABLE=1       hopla complete bash

# only print autocomplete for bash
HOPLA_COMPLETE_ENABLE=0       hopla complete bash   
HOPLA_COMPLETE_ENABLE=false   hopla complete bash   
HOPLA_COMPLETE_ENABLE=no      hopla complete bash   

Add unit tests (Generic ticket)

Note: Keep PRs small. 1-100 lines is the sweet spot. <400 lines definitely.
Make a copy of this ticket for adding more unit tests.

add introduction gif to README.md

Tasks

  • Add a gif to the README.md showing :
    • install command
    • configure command
    • 2-3 simple commands
  • put it in a prominent place (at the top)

Create the pypi release

steps:

  • update to version 0.0.13.
  • tag the commit
  • Make a github release
  • make a pypi release

Refactor hopla authorization

Currently, way too much code is used for something simple.
This has to do with the migration from bash.
Now we use a different config file format, for which python has a lot of support. Use that instead.

hopla --version does not work properly

when installed with pip:

$ hopla --version
Traceback (most recent call last):
  File "/home/m/.local/lib/python3.8/site-packages/click/decorators.py", line 379, in callback
    version = metadata.version(package_name)  # type: ignore
  File "/usr/lib/python3.8/importlib/metadata.py", line 530, in version
    return distribution(distribution_name).version
  File "/usr/lib/python3.8/importlib/metadata.py", line 503, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/lib/python3.8/importlib/metadata.py", line 177, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: hopla

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/m/.local/bin/hopla", line 8, in <module>
    sys.exit(entry_cmd())
  File "/home/m/.local/lib/python3.8/site-packages/hopla/__init__.py", line 78, in entry_cmd
    hopla()
  File "/home/m/.local/lib/python3.8/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/m/.local/lib/python3.8/site-packages/click/core.py", line 1061, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/home/m/.local/lib/python3.8/site-packages/click/core.py", line 923, in make_context
    self.parse_args(ctx, args)
  File "/home/m/.local/lib/python3.8/site-packages/click/core.py", line 1624, in parse_args
    rest = super().parse_args(ctx, args)
  File "/home/m/.local/lib/python3.8/site-packages/click/core.py", line 1379, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/home/m/.local/lib/python3.8/site-packages/click/core.py", line 2364, in handle_parse_result
    value = self.process_value(ctx, value)
  File "/home/m/.local/lib/python3.8/site-packages/click/core.py", line 2326, in process_value
    value = self.callback(ctx, self, value)
  File "/home/m/.local/lib/python3.8/site-packages/click/decorators.py", line 381, in callback
    raise RuntimeError(
RuntimeError: 'hopla' is not installed. Try passing 'package_name' instead.

Local install:

$ hopla --version
hopla, version 0.0.12a0

Set config default defaults

I believe python-click has some nice functionality for this.

Currently we only have the cmd_all.loglevel config variable. (Also consider if you want to change this name within the scope of this ticket, or if you want to in another ticket, or do this at all.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.