Resolves: #1574835 - make units_cur work again

This commit is contained in:
Kamil Dudka 2018-05-28 14:24:33 +02:00
parent 9cac3b9e2d
commit 8200b417c0
2 changed files with 88 additions and 2 deletions

View File

@ -0,0 +1,80 @@
From 29b4b1ac90bfe54f1d7d83a3b3e4e1a1305332fa Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@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

View File

@ -1,7 +1,7 @@
Summary: A utility for converting amounts from one unit to another
Name: units
Version: 2.16
Release: 4%{?dist}
Release: 5%{?dist}
Source: https://ftp.gnu.org/gnu/units/%{name}-%{version}.tar.gz
URL: https://www.gnu.org/software/units/units.html
License: GPLv3+
@ -17,6 +17,9 @@ BuildRequires: readline-devel
# used by the units_cur script
Requires: python3-unidecode
# make units_cur work again (#1574835)
Patch1: 0001-units-2.16-units_cur.patch
%description
Units converts an amount from one unit to another, or tells you what
mathematical operation you need to perform to convert from one unit to
@ -24,7 +27,7 @@ another. The units program can handle multiplicative scale changes as
well as conversions such as Fahrenheit to Celsius.
%prep
%setup -q
%autosetup -p1
# make units_cur use Python 3
sed -e 's|^AC_PATH_PROG(PYTHON, python|&3|' -i configure.ac
@ -64,6 +67,9 @@ fi
%{_mandir}/man1/*
%changelog
* Mon May 25 2018 Kamil Dudka <kdudka@redhat.com> - 2.16-5
- make units_cur work again (#1574835)
* Mon Feb 19 2018 Kamil Dudka <kdudka@redhat.com> - 2.16-4
- add explicit BR for the gcc compiler