Jump to content

Currency Converter


Recommended Posts

This tool helps you with currency conversion

 

For example, convert 100 USD to EUR:

2022-03-11-080455.thumb.png.d058c0c688a38fb5b3968be51c20b4ef.png

 

check here: https://github.com/y1nglamore/AlfredCurrencyConverter

 

btw, it needs your python has requests module. you can try `python -c "import requests"` on bash , if it don't tell you 'ImportError: No module named requests' that means you have the `requests` module. Otherwise, use `pip install requests` to install it

Edited by Y1ng
add some detail
Link to comment
9 hours ago, vitor said:

@leophegor When asking for help, be sure to include the debugger output, otherwise @Y1ng can’t know what’s wrong in your particular case.

 

Welcome to the forums.

Here's the output of debugger.

 

[11:28:17.241] Currency Converter[Script Filter] Queuing argument '1'

[11:28:17.354] Currency Converter[Script Filter] Script with argv '1' finished

[11:28:17.356] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:17.534] Currency Converter[Script Filter] Queuing argument '10'

[11:28:17.601] Currency Converter[Script Filter] Script with argv '10' finished

[11:28:17.604] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:19.306] Currency Converter[Script Filter] Queuing argument '100'

[11:28:19.380] Currency Converter[Script Filter] Script with argv '100' finished

[11:28:19.384] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:20.709] Currency Converter[Script Filter] Queuing argument '100U'

[11:28:20.851] Currency Converter[Script Filter] Script with argv '100U' finished

[11:28:20.857] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:20.904] Currency Converter[Script Filter] Queuing argument '100US'

[11:28:21.027] Currency Converter[Script Filter] Script with argv '100US' finished

[11:28:21.033] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:21.214] Currency Converter[Script Filter] Queuing argument '100USD'

[11:28:21.288] Currency Converter[Script Filter] Script with argv '100USD' finished

[11:28:21.293] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:21.951] Currency Converter[Script Filter] Queuing argument '100USD '

[11:28:22.021] Currency Converter[Script Filter] Script with argv '100USD ' finished

[11:28:22.028] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:22.314] Currency Converter[Script Filter] Queuing argument '100USD C'

[11:28:22.445] Currency Converter[Script Filter] Script with argv '100USD C' finished

[11:28:22.455] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:22.650] Currency Converter[Script Filter] Queuing argument '100USD CN'

[11:28:22.792] Currency Converter[Script Filter] Script with argv '100USD CN' finished

[11:28:22.801] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:22.871] Currency Converter[Script Filter] Queuing argument '100USD CNY'

[11:28:22.994] Currency Converter[Script Filter] Script with argv '100USD CNY' finished

[11:28:23.003] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

Link to comment
5 hours ago, leophegor said:

Here's the output of debugger.

 

[11:28:17.241] Currency Converter[Script Filter] Queuing argument '1'

[11:28:17.354] Currency Converter[Script Filter] Script with argv '1' finished

[11:28:17.356] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:17.534] Currency Converter[Script Filter] Queuing argument '10'

[11:28:17.601] Currency Converter[Script Filter] Script with argv '10' finished

[11:28:17.604] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:19.306] Currency Converter[Script Filter] Queuing argument '100'

[11:28:19.380] Currency Converter[Script Filter] Script with argv '100' finished

[11:28:19.384] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:20.709] Currency Converter[Script Filter] Queuing argument '100U'

[11:28:20.851] Currency Converter[Script Filter] Script with argv '100U' finished

[11:28:20.857] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:20.904] Currency Converter[Script Filter] Queuing argument '100US'

[11:28:21.027] Currency Converter[Script Filter] Script with argv '100US' finished

[11:28:21.033] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:21.214] Currency Converter[Script Filter] Queuing argument '100USD'

[11:28:21.288] Currency Converter[Script Filter] Script with argv '100USD' finished

[11:28:21.293] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:21.951] Currency Converter[Script Filter] Queuing argument '100USD '

[11:28:22.021] Currency Converter[Script Filter] Script with argv '100USD ' finished

[11:28:22.028] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:22.314] Currency Converter[Script Filter] Queuing argument '100USD C'

[11:28:22.445] Currency Converter[Script Filter] Script with argv '100USD C' finished

[11:28:22.455] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:22.650] Currency Converter[Script Filter] Queuing argument '100USD CN'

[11:28:22.792] Currency Converter[Script Filter] Script with argv '100USD CN' finished

[11:28:22.801] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

[11:28:22.871] Currency Converter[Script Filter] Queuing argument '100USD CNY'

[11:28:22.994] Currency Converter[Script Filter] Script with argv '100USD CNY' finished

[11:28:23.003] ERROR: Currency Converter[Script Filter] Code 1: Traceback (most recent call last):

  File "run.py", line 1, in <module>

    import requests

ImportError: No module named requests

That is because your python miss requests module. use `pip install requests` to install it 

Link to comment

If Afread Debug saild "ImportError: No module named requests" and `pip install requests` dont work, Try there steps:

 

First, check if you have python and pip on you Mac, or use brew to install. 

 

Second, you may still get ImportError when you have already `pip install requests`, that may because you have many python(such as 2.7 3.5 3.7 3.9), The python which installed requests module is different from the python alfred use. Then you can find the right python's path by using `whereis python` `which python` or other ways,  then edit the workflow:

WeChat43ede7f9b99a8b97def040d2094a8105.png.6f3a0eb4e2a62feea6415814f3e4eecc.pngWX20220312-171352.png.37f6da43b3b1bcb38898cf5d6c6f92fd.pngWX20220312-171352.png.37f6da43b3b1bcb38898cf5d6c6f92fd.png

Link to comment
1 hour ago, Y1ng said:

use `pip install requests` to install it

 

It's not a standard package, so you should bundle it with the workflow. Asking non-technical users to install software libraries when you could easily bundle them isn't great.

 

And, that's not a great way to install requests, either. You should always call pip via /path/to/python -m pip, so you know which Python you’re installing the packages in. There’s no telling what will get called if you just run pip because different Pythons all want to use /usr/local/bin/pip and will overwrite each other.

 

Alfred also doesn’t use the same PATH as your shell, so python won’t be the same command in Alfred as in a shell. So use the full path to the Python executable.

 

Finally, you shouldn’t install packages globally like that. Install them in your user-specific library folder, so you aren’t changing the system and don’t need admin rights: /path/to/python -m pip install --user requests

Link to comment
55 minutes ago, deanishe said:

 

It's not a standard package, so you should bundle it with the workflow. Asking non-technical users to install software libraries when you could easily bundle them isn't great.

 

And, that's not a great way to install requests, either. You should always call pip via /path/to/python -m pip, so you know which Python you’re installing the packages in. There’s no telling what will get called if you just run pip because different Pythons all want to use /usr/local/bin/pip and will overwrite each other.

 

Alfred also doesn’t use the same PATH as your shell, so python won’t be the same command in Alfred as in a shell. So use the full path to the Python executable.

 

Finally, you shouldn’t install packages globally like that. Install them in your user-specific library folder, so you aren’t changing the system and don’t need admin rights: /path/to/python -m pip install --user requests

You are right, thank you !

 

I just use Alfred for 1 week and it is my first workflow, so it may have lots of issues, i will optimize it when im familiar with writing workflows

Link to comment

thank you, this is super helpful!

If we do want the user to install a nonstandard package with /path/to/python -m pip install --user myPackage, how do we point to the package (i.e. how do we get /path/to/python) in the workflow? Is there a way to point to the most recent Python installation, or should we ask the user to run which python and then enter the path in a workflow variable?

 

also, should we use pip3 (and which python3) going forward?

Edited by giovanni
Link to comment
10 minutes ago, giovanni said:

If we do want the user to install a nonstandard package with /path/to/python -m pip install --user myPackage, how do we point to the package (i.e. how do we get /path/to/python) in the workflow?

 

You don’t. That paragraph applies in general, like installing it for yourself. If it’s for a Workflow, follow the first paragraph: bundle the package with the Workflow instead of asking the user to install it. That is significantly easier for users because they don’t have anything to setup and is beneficial to you because you know what version is used.

 

It should be something like /path/to/python -m pip install --target "/CUSTOM/DIRECTORY/PATH" "PACKAGE_NAME" and then using export PYTHONPATH="/CUSTOM/DIRECTORY/PATH" before calling your script to ensure the package is available.

 

13 minutes ago, giovanni said:

Is there a way to point to the most recent Python installation

 

Not really. You can try to guess but that doesn’t give you guarantees. A user may have, at the same time, /usr/bin/python3 (from the developer tools), /opt/homebrew/bin/python3 (installed as a dependency for another Homebrew package), and ~/.pyenv/shims/python3 (version-managed with pyenv). They may have only wanted (and directly use) the last one, but the others exist nonetheless (cue XKCD).

 

19 minutes ago, giovanni said:

or should we ask the user to run which python and then enter the path in a workflow variable?

 

You want to avoid that, for the benefit of both users and yourself. Extra manual steps you require, especially technical ones, increase your support burden. You should either use /usr/bin/python3 directly (macOS will prompt the user to install it if they don’t have it, and that’s done in two clicks) or require a Homebrew-installed Pyhton and use that path (not directly, use export PATH="/opt/homebrew/bin:/usr/local/bin:${PATH}" due to the different Homebrew locations).

 

@Y1ng Since you’re just calling python, this point is particularly relevant. Starting next week, with the release of macOS Monterey 12.3, that will no longer be available.

 

16 minutes ago, giovanni said:

also, should we use pip3 (and which python3) going forward?

 

Yes, you shouldn’t be using Python 2 anymore. Or anything below 3.6, for that matter.

Link to comment
22 minutes ago, vitor said:

If it’s for a Workflow, follow the first paragraph: bundle the package with the Workflow instead of asking the user to install it.

thank you!! what if the package has a ton of dependancies? Case in point (to avoid the XY problem 😆): I have made a workflow to access my Audible library using this unofficial API and I would like to share it. I had in my setup instructions to install with pip3 install audible-cli and then pointed to the package using ~/Library/Python/3.8/bin/audible-cli (or ask the user to enter the path to Python) but I was wondering if there is a better, more future-proof way. 

Thanks again both for educating us!

 

Link to comment
3 hours ago, giovanni said:

I was wondering if there is a better, more future-proof way.

 

Short answer: bundle the dependencies. Lower the need to rely on the user’s environment.

 

Long answer is below. With apologies to @Y1ng for having this long post in your Workflow’s thread. If you prefer, I can split these to another.

 

3 hours ago, giovanni said:

what if the package has a ton of dependancies?

 

What specifically worries you in that scenario? Is it the extra size? I just downloaded it to a temporary directory with dependencies and it came to just under 20MB. Granted, that isn’t small, but is it worse than the alternative?


Consider your case under the multi-python scenario in my previous comment. You ask a user to pip3 install audible-cli and they now have it under a Python that is managed by pyenv. But because (let’s imagine) the Workflow is assuming a Homebrew Python installation, it doesn’t pick it up and appears broken. What do you do then? You can refine your instructions to specify a Homebrew Python needs to be used, but considering a multitude of possible setups and that the path to a Homebrewed Python changes depending on architecture, you’re now spending half of the “About” from your Workflow explaining technical details which are irrelevant to most. Or you can have a Workflow Environment Variable where users add a custom Python path, and now you need to do a bunch of checks to ensure it exists, and how to react when it doesn’t, and the Python path is now dynamic and your code is harder to maintain. Or you can make your Workflow 20MB larger.


What’s the best option? It depends. What do you value most? What do you believe the users of your Workflow value most? How close to your ideals can your current level of skill take you? How do different goals correlate? Is a 1MB increase in file size worth it for a program 100 times faster? What about 100MB for something 1.5 times faster? What about 20MB for extra convenience? How do you even measure convenience?


There is always a tradeoff. Your goal is to identify and pick the best one for your situation.


Let’s keep exploring your specific case from a size perspective. Python is popular. If every Python Workflow included a full runtime—even if it were small—the duplication would lead to considerable wasted bandwidth and space (including in the user’s cloud hosting, for synced settings). But what about audible-cli, how likely is it that a user of your Workflow already has it installed, for another Workflow or in general? If they’re more likely to not have it (seems likely), is the extra size worth skipping the hassle of having to set it up? For under 20MB, I’d say yes; if it were 500MB, I’d say no. But even that is relative. How much of a hassle are you saving?


Will a user not use your Workflow because it’s hard to setup? Will another not use it because its file size is too big? Both can be true. Which of those weighs more? Which choice will make a better Workflow for most people? Which one will make a better Workflows for yourself, one that you’ll continue to have fun developing and be proud to offer support for, which will in turn be better for users?


There are answers to all of these questions. Though yours may be different than mine and they may change with time.

 

Apologies for the length of the post. Given more time I’d have made it shorter and all that, but it’s dinner time. Have a nice evening.

Link to comment

thank you @vitor for taking the time to explain. Super clear and thoughtful as always.  

Yes, in general my concern was size and potential for duplication, which I realize might not always apply.

 

In this particular case, the workflow setup requires authentication with Audible through the command line, which I don't know how to launch without installing the package. Perhaps I can start with a package installation in a first release of the workflow, and then ask for help on here to streamline installation for the end user. 

Thanks again!

Link to comment
  • 1 month later...

@vitorgoing back to this discussion, I tried to bundle everything in the lib folder with pip3 install -r requirements.txt --target=lib (which has worked for me so far), but couldn't get it to work for this particular package, with many dependancies (one of the errors was /lib/PIL/_imaging.cpython-38-darwin.so' not valid for use in process: library load disallowed by system policy)

So, as a compromise, I require to user to have pip3  installed and then I make Alfred install the libraries with pip3 install -r requirements.txt --target=lib

I also added your OneUpdater (thank you!) so I can fix if I find a better solution at some point.

Thanks again for your input!

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...