Package: units Version: 2.16-2 Severity: important Tags: upstream patch Dear Maintainer,
units_cur as packaged is currently broken due to changes from the yahoo service that is being scraped. Output is as follows: Traceback (most recent call last): File "/usr/bin/units_cur", line 261, in <module> rates = [ data['resource']['fields']['price'] for data in webdata] File "/usr/bin/units_cur", line 261, in <listcomp> rates = [ data['resource']['fields']['price'] for data in webdata] KeyError: 'price' Redhat bug: https://bugzilla.redhat.com/show_bug.cgi?id=1574835 Upstream patch: https://src.fedoraproject.org/cgit/rpms/units.git/plain/0001-units-2.16-units_cur.patch?id=8200b417 units_cur with this patch now works for me. Thank you. -Chris -- System Information: Debian Release: 8.10 APT prefers oldstable-updates APT policy: (500, 'oldstable-updates'), (500, 'oldstable') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 4.9.0-0.bpo.6-amd64 (SMP w/4 CPU cores) Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: sysvinit (via /sbin/init) Versions of packages units depends on: ii libc6 2.19-18+deb8u10 ii libreadline7 7.0-3 Versions of packages units recommends: ii python3 3.4.2-2 ii python3-requests 2.11.1-1~bpo8+1 units suggests no packages. -- no debconf information -- debsums errors found: debsums: changed file /usr/bin/units_cur (from units package) debsums: changed file /usr/share/units/currency.units (from units package)
>From 29b4b1ac90bfe54f1d7d83a3b3e4e1a1305332fa Mon Sep 17 00:00:00 2001 From: Kamil Dudka <kdu...@redhat.com> Date: Mon, 28 May 2018 14:21:35 +0200 Subject: [PATCH] Resolves: #1574835 - make units_cur work again --- units_cur | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/units_cur b/units_cur index 5541355..d00c12c 100755 --- a/units_cur +++ b/units_cur @@ -5,14 +5,17 @@ from __future__ import absolute_import, division, print_function # # -version = '4.1' +version = '4.2' -# 30 October 2017 +# Version 4.2: 18 April 2018 +# +# Handle case of empty/malformed entry returned from the server +# +# Version 4.1: 30 October 2017 # # Fixed to include USD in the list of currency codes. # -# Version 4 -# 2 October 2017 +# Version 4: 2 October 2017 # # Complete rewrite to use Yahoo YQL API due to removal of TimeGenie RSS feed. # Switched to requests library using JSON. One program now runs under @@ -258,22 +261,27 @@ except requests.exceptions.RequestException as e: format(e)) exit(1) -rates = [ data['resource']['fields']['price'] for data in webdata] -codes = [ data['resource']['fields']['symbol'][0:3] for data in webdata] rate_index = 1 - -for (code,rate) in zip(codes,rates): - if code not in currency.keys(): - if (verbose): - stderr.write('Got unknown currency with code {}\n'.format(code)) - else: - if not currency[code][rate_index]: - currency[code][rate_index] = '1|{} US$'.format(rate) - elif verbose: - stderr.write('Got value "{}" for currency "{}" but ' - 'it is already defined\n'.format(rate, code)) - +for data in webdata: + entry = data['resource']['fields'] + if 'price' not in entry or 'symbol' not in entry: # Skip empty/bad entries + if verbose: + stderr.write('Got bad entry from server: '+str(entry)+'\n') + else: + rate = entry['price'] + code = entry['symbol'][0:3] + if code not in currency.keys(): + if (verbose): + stderr.write('Got unknown currency with code {}\n'.format(code)) + else: + if not currency[code][rate_index]: + currency[code][rate_index] = '1|{} US$'.format(rate) + elif verbose: + stderr.write('Got value "{}" for currency "{}" but ' + 'it is already defined\n'.format(rate, code)) + + # Delete currencies where we have no rate data for code in currency.keys(): if not currency[code][rate_index]: -- 2.14.3