glgray Posted November 29, 2013 Share Posted November 29, 2013 The built-in list of units is here: https://github.com/hgrecco/pint/blob/master/pint/default_en.txt. My additions are here: https://github.com/jason0x43/jc-units/blob/master/unit_defs.txt. I just added "C" and "F" for temperature (different names) and a definition for hectare (just for fun). The unit system is easy to extend, although it doesn't seem to automatically handle unit name clashes. I have some simple logic in the workflow to deal with situations like "u 1cup>oz", where the unit name "oz" refers to weight ounces, but we mean fluid ounces. Basically I have a table of alternate possibilities for some unit names. If a conversion fails and either the source or destination units are in the table, the converter tries again with the alternate units. Awesome. Awesome. Awesome! This is going to be incredibly handy. Thank you again. Link to comment
jason0x43 Posted November 29, 2013 Author Share Posted November 29, 2013 (edited) Currency conversion is back. I'm using the Yahoo! Finance API to get current rates. The workflow will download the most recent rates the first time you use it each day. Currency units are the standard 3-letter abbreviations for currency names (US dollar is USD, Australian dollar is AUD, yen is JPY, etc.). Edited November 29, 2013 by jason0x43 Link to comment
vitor Posted November 30, 2013 Share Posted November 30, 2013 Currency conversion is back. I'm using the Yahoo! Finance API to get current rates. The workflow will download the most recent rates the first time you use it each day. Currency units are the standard 3-letter abbreviations for currency names (US dollar is USD, Australian dollar is AUD, yen is JPY, etc.). You seem to be missing euros (EUR). On another note, is there an easy way to change the string that tells it to convert? I’d like to change > to to. Link to comment
jason0x43 Posted December 1, 2013 Author Share Posted December 1, 2013 You seem to be missing euros (EUR). On another note, is there an easy way to change the string that tells it to convert? I’d like to change > to to. Oops. Euros are in there now. You can now use the 'u>' command to list extra commands, including 'Open config file...'. This is a JSON formatted file. The only two options it currently understands are log_file and "separator". Change separator to "to" and you should be in good shape. If you change a value using Apple's TextEdit, make sure it doesn't change your double quotes to rich text quote marks. Those make the JSON parser cry. Link to comment
pitterpoehse Posted December 1, 2013 Share Posted December 1, 2013 Is it possible to change the separator back to just a space? When I change the separator in the config file to a space it does not work. Thank you! Link to comment
jason0x43 Posted December 1, 2013 Author Share Posted December 1, 2013 I uploaded an update with support for this. Using a space as the separator can lead to ambiguous queries. For example, "1 pint imperial pint" will be understood as "convert 1 pint imperial to pints", which isn't what was intended. To get around that, you can use underscores in the names of units that have spaces if you're using space as the separator: "1 pint imperial_pint". If you're using a unique character, like '>', you can just do "1pint>imperial pint". Link to comment
pitterpoehse Posted December 1, 2013 Share Posted December 1, 2013 For me the new version you uploaded doesn't work anymore at all. Whatever I plug in the configuration file, e.g. "u 10 eur usd", respectively "u 10 eur>usd" whether it's ">" or " ", I just get "Waiting for input...". Link to comment
jason0x43 Posted December 1, 2013 Author Share Posted December 1, 2013 For me the new version you uploaded doesn't work anymore at all. Whatever I plug in the configuration file, e.g. "u 10 eur usd", respectively "u 10 eur>usd" whether it's ">" or " ", I just get "Waiting for input...". Sorry about that. My new query parsing code didn't handle spaces at the beginning of the query properly. Try it now. Link to comment
pitterpoehse Posted December 1, 2013 Share Posted December 1, 2013 Awesome, thank you so much! Link to comment
vitor Posted December 1, 2013 Share Posted December 1, 2013 The separator change works pretty well, thank you.I still cannot get EUR conversions (I just get waiting for input). Other currency conversions seem to work fine, though. Link to comment
jason0x43 Posted December 2, 2013 Author Share Posted December 2, 2013 The currency cache updates once a day. If you tried it before I added EUR conversions, it wouldn't refresh until the next day. (I should probably add a cache clearing command for that...) Link to comment
vitor Posted December 2, 2013 Share Posted December 2, 2013 The currency cache updates once a day. If you tried it before I added EUR conversions, it wouldn't refresh until the next day. (I should probably add a cache clearing command for that...) I had actually cleared the cache directory before, so I thought that couldn’t be the problem, but just realised I deleted it before you added EUR support. It’s working now, thank you. Link to comment
jaster Posted December 7, 2013 Share Posted December 7, 2013 Is there any way to change the length of the output? Something like '3.0101' rather than '3.01013143483' Link to comment
jason0x43 Posted December 7, 2013 Author Share Posted December 7, 2013 Is there any way to change the length of the output? Something like '3.0101' rather than '3.01013143483' There is now. Use the "u>" command to open the config file, then change the "precision" option to a positive number and save it. Link to comment
jaster Posted December 8, 2013 Share Posted December 8, 2013 There is now. Use the "u>" command to open the config file, then change the "precision" option to a positive number and save it. Awesome! Thank you so much. Link to comment
vitor Posted December 8, 2013 Share Posted December 8, 2013 Posting just to thank you for being so active on this. It’s great to see a developer being so responsive about feature requests, without breaking the flow of people who already use the workflow. Link to comment
sudopeople Posted February 3, 2014 Share Posted February 3, 2014 Math doesn't seem to be working for me: Link to comment
jason0x43 Posted February 5, 2014 Author Share Posted February 5, 2014 I'm away from my system at the moment, but I'll check on that and get back to you. Link to comment
jason0x43 Posted February 7, 2014 Author Share Posted February 7, 2014 Ok, I don't remember breaking unit math, but I totally did. I just uploaded a new version that restores that feature. Link to comment
vikas.mishra Posted March 8, 2014 Share Posted March 8, 2014 (edited) Hello, A couple of questions/comments 1. For some reason the unit math is still not working for me. I just downloaded the workflow again today. Error log is below >> [2014-03-07 16:31:09,166] INFO: convert: loading definitions from /Users/vikasmis/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/jc-units/currencies.txt [2014-03-07 16:31:09,170] ERROR: alfred_convert: Error converting Traceback (most recent call last): File "alfred_convert.py", line 89, in _convert value, text = self.converter.convert(query) File "convert.py", line 48, in convert in_val = Q_(value) File "pint/quantity.py", line 121, in __new__ inst = cls._REGISTRY.parse_expression(value) File "pint/unit.py", line 1022, in parse_expression raise UndefinedUnitError(unknown) UndefinedUnitError: 'i' is not defined in the unit registry >> 2. In addition I have realized that if I have a space between the number and units, it doesn't work. For example - "u 5km > miles" works but "u 5 km > miles" doesn't work. Is this intentional? If so, may help to add a comment to the top post. Regards, Vikas Edited March 8, 2014 by vikas.mishra Link to comment
jason0x43 Posted March 13, 2014 Author Share Posted March 13, 2014 What does your input look like? A valid string is something along the lines of "u 1mi + 1m > m", which would add 1 mile and 1 meter and output in meters. No, that's not intentional. I'll look into that. Link to comment
valon Posted April 23, 2014 Share Posted April 23, 2014 Hi, I'm getting this error. It is present only when I'm on LAN behind proxy server (system wide proxy server setting, http, https and socks proxy). Is there any workaround? [ERROR: alfred.workflow.input.scriptfilter] Code 1: Traceback (most recent call last): File "<string>", line 2, in <module> File "alfred_convert.py", line 54, in __init__ self.load_currencies() File "alfred_convert.py", line 79, in load_currencies rates = yfinance.get_rates(CURRENCIES) File "yfinance.py", line 22, in get_rates response = requests.get(API, params=params) File "requests/api.py", line 55, in get return request('get', url, **kwargs) File "requests/api.py", line 44, in request return session.request(method=method, url=url, **kwargs) File "requests/sessions.py", line 335, in request resp = self.send(prep, **send_kwargs) File "requests/sessions.py", line 438, in send r = adapter.send(request, **kwargs) File "requests/adapters.py", line 327, in send raise ConnectionError(e) requests.exceptions.ConnectionError: HTTPConnectionPool(host='query.yahooapis.com', port=80): Max retries exceeded with url: /v1/public/yql?q=select+Name%2C+Rate+from+yahoo.finance.xchange+where+pair%3D%27AUD%2CBGN%2CBRL%2CCAD%2CCHF%2CCNY%2CCZK%2CDKK%2CEUR%2CGBP%2CHKD%2CHRK%2CHUF%2CIDR%2CILS%2CINR%2CJPY%2CKRW%2CLTL%2CLVL%2CMXN%2CMYR%2CNOK%2CNZD%2CPHP%2CPLN%2CRON%2CRUB%2CSEK%2CSGD%2CTHB%2CTRY%2CZAR%27&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&format=json (Caused by <class 'socket.error'>: [Errno 61] Connection refused) Link to comment
deanishe Posted April 25, 2014 Share Posted April 25, 2014 (edited) I imagine you'll have the same problem with most workflows that access the network. At least for Python workflows, making sure the http_proxy environmental variable is correctly set will ensure workflows use the proxy. This is a bit complicated to set, however. On Mavericks, you need to set it in the launchd environment (see here). For earlier versions, you can use environment.plist. If you only have a small number of workflows, you can fix it on a per-workflow basis. For this one, you'll need to edit the two Script Filters and the Run Script action and add the following at the top of the script box: import os os.environ['http_proxy'] = 'http://192.168.0.1:3128' changing http://192.168.0.1:3128 to whatever the IP address/hostname and port of your proxy server is. Edited April 25, 2014 by deanishe Link to comment
jaster Posted May 22, 2014 Share Posted May 22, 2014 What part of which file would I have to modify in order for it to allow a space between the value and unit (for every query, not just currencies)? For example rather than u 20usd to aud I'd like it be u 20 usd to aud Thanks. Link to comment
jason0x43 Posted May 22, 2014 Author Share Posted May 22, 2014 What part of which file would I have to modify in order for it to allow a space between the value and unit (for every query, not just currencies)? For example rather than u 20usd to aud I'd like it be u 20 usd to aud Thanks. I just pushed an update that supports this. The code that processes the input is in convert.py. I do some very naive string pre-processing to allow unit names to contain spaces, and it was also combining the number with its units. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now