Giter VIP home page Giter VIP logo

Comments (5)

Dianelynn1 avatar Dianelynn1 commented on August 27, 2024

Because I don’t have any experience in programming, I hope you can explain in detail how I can operate or modify your workflow if you can help me.

Thanks again!

from alfred-converter.

wolph avatar wolph commented on August 27, 2024

There are 2 ways to add new units to the system.

  1. By editing this bit of code: https://github.com/WoLpH/alfred-converter/blob/master/converter/extra_units.py
  2. By editing the units XML file: https://github.com/WoLpH/alfred-converter/blob/master/poscUnits22.xml

When editing the extra_units.py file I think you would need something like this as part of the register_post function:

convert.Unit(
  id='dollar',
  name='Dollar',
  annotations=['$', 'dollar'],
  conversion_params=('0', '0', '1', '0'),
).register(units)

convert.Unit(
  id='paypal-fee',
  name='PayPal fee',
  base_unit='dollar',
  conversion_params=('0.3', '0.044', '1', '0'),

Note: the conversion params work like this: (a + b * value) / (c + d * value)

Perhaps I'll add something in the future to make this easier, but for now that's the only option. You're the first to ask for a custom unit :)

from alfred-converter.

Dianelynn1 avatar Dianelynn1 commented on August 27, 2024

I compared your new code formats and put them in this section of the extra_units.py file.

But I still don’t seem to add them correctly, because PP-fee is not available in the Alfred 4

image

image
Is this because I put the code in the wrong place or is it just that Alfred made a mistake about using the PP hotkey?

Sorry for taking your time again.

from alfred-converter.

wolph avatar wolph commented on August 27, 2024

It seems I somehow missed your reply... sorry about that

In any case, it looks like my example was a bit too limited to work. I've tried a little more and I've come up with this code:

    params = dict(
        units=units,
        quantity_types=['money'],
        base_unit='dollar',
    )

    add = 0.3
    fee = 4.4
    multiplier = fee * 0.0105
    convert.Unit(
        id='dollar',
        name='Dollar',
        annotations=['$', 'dollar'],
        conversion_params=('0', '1', '1', '0'),
        **params
    ).register(units)

    convert.Unit(
        id='paypal-fee',
        name='PayPal fee',
        annotations=['pp', 'paypal'],
        conversion_params=('-%s' % add, '1', str(multiplier), '0'),
        **params
    ).register(units)

    convert.Unit(
        id='paypal-total',
        name='PayPal Total',
        annotations=['pt'],
        conversion_params=('-%s' % add, '1', str(1 + multiplier), '0'),
        **params
    ).register(units)

If needed you can easily change the 4.4% and +0.3. Note that after editing the code you will have to delete the units.pickle file which caches the calculations.

This is how it looks right now:
image

from alfred-converter.

Dianelynn1 avatar Dianelynn1 commented on August 27, 2024

from alfred-converter.

Related Issues (20)

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.