diff --git a/nasdaq_uvoljs.py b/nasdaq_uvoljs.py index 57b36f4..7711a5d 100644 --- a/nasdaq_uvoljs.py +++ b/nasdaq_uvoljs.py @@ -160,19 +160,23 @@ def build_df(self, ud): co_name_lj = (re.sub('[\']', '', co_name_lj) ) # remove " ' and strip leading/trailing spaces price_cl = (re.sub('[ $,]', '', price)) # remove $ sign - price_net_cl = (re.sub(r'[\-+]', '', price_net)) # remove - + signs - price_pct_cl = (re.sub(r'[\-+%]', '', price_pct)) # remove - + % signs + price_net_cl = (re.sub(r'[\+]', '', price_net)) # remove + sign, preserve - + price_pct_cl = (re.sub(r'[\+%]', '', price_pct)) # remove +/% signs, preserve - vol_abs_cl = (re.sub('[,]', '', vol_abs)) # remove , vol_abs_cl = (re.sub('[,]', '', vol_abs)) # remove , vol_pct_cl = (re.sub('[%]', '', vol_pct)) # remover % + price_net_clean = round(float(price_net_cl), 2) + price_pct_clean = round(float(price_pct_cl), 2) + if price_net_clean < 0 and price_pct_clean > 0: + price_pct_clean = -price_pct_clean self.list_data = [[ \ x, \ re.sub('\'', '', co_sym_lj), \ co_name_lj, \ round(float(price_cl), 2), \ - round(float(price_net_cl), 2), \ - round(float(price_pct_cl), 2), \ + price_net_clean, \ + price_pct_clean, \ round(float(vol_abs_cl)), \ round(float(vol_pct_cl), 1), \ time_now ]] diff --git a/nasdaq_wrangler.py b/nasdaq_wrangler.py index 36f29df..f64019d 100644 --- a/nasdaq_wrangler.py +++ b/nasdaq_wrangler.py @@ -403,8 +403,8 @@ def clean_cast(self): logging.info('%s - Price NET is unchanged' % cmi_debug ) cc_errors += 1 else: - self.price_net_cl = (re.sub(r'[\-+]', '', self.price_net)) # remove - + signs - self.price_net_cl = float(self.price_net) + self.price_net_cl = (re.sub(r'[\+,]', '', self.price_net)) # remove +/, signs, preserve - + self.price_net_cl = float(self.price_net_cl) if self.price_pct == "N/A": self.price_pct_cl = float(0) @@ -419,8 +419,10 @@ def clean_cast(self): logging.info('%s - Price pct is bad, field is Null/empty' % cmi_debug ) cc_errors += 1 else: - self.price_pct = (re.sub(r'[\-+%]', '', self.price_pct)) # remove - + % signs + self.price_pct = (re.sub(r'[\+%,]', '', self.price_pct)) # remove +/%/, signs, preserve - self.price_pct_cl = float(self.price_pct) + if self.price_net_cl < 0 and self.price_pct_cl > 0: + self.price_pct_cl = -self.price_pct_cl # ################# open price(s) need extra treatment & care... """ diff --git a/y_daylosers.py b/y_daylosers.py index 8b49c1c..4cf9ae7 100644 --- a/y_daylosers.py +++ b/y_daylosers.py @@ -175,13 +175,18 @@ def extr_gen(): co_name_lj = (re.sub(r'[\'\"]', '', co_name_lj) ) # remove " ' and strip leading/trailing spaces price_cl = (re.sub(r'\,', '', price)) # remove , price_clean = float(price_cl) - change_clean = float(change_val) + change_sign_multiplier = -1 if change_sign == "-" or str(change_val).strip().startswith("-") else 1 + change_cl = re.sub(r'[\+\-,]', "", str(change_val)) + change_clean = float(change_cl) * change_sign_multiplier if pct_val == "N/A": - pct_val = float(0.0) # Bad data. FOund a filed with N/A instead of read num + pct_clean = float(0.0) # Bad data. FOund a filed with N/A instead of read num else: + pct_sign_multiplier = -1 if pct_sign == "-" or str(pct_val).strip().startswith("-") else 1 pct_cl = re.sub(r'[\%\+\-,]', "", pct_val ) - pct_clean = float(pct_cl) + pct_clean = float(pct_cl) * pct_sign_multiplier + if change_clean < 0 and pct_clean > 0: + pct_clean = -pct_clean ################################ 5 #################################### mktcap = (re.sub(r'[N\/A]', '0', mktcap)) # handle N/A diff --git a/y_smallcaps.py b/y_smallcaps.py index a3802fe..4baf03f 100644 --- a/y_smallcaps.py +++ b/y_smallcaps.py @@ -200,13 +200,18 @@ def extr_gen(): co_name_lj = (re.sub(r'[\'\"]', '', co_name_lj) ) # remove " ' and strip leading/trailing spaces price_cl = (re.sub(r'\,', '', price)) # remove , price_clean = float(price_cl) - change_clean = float(change_val) + change_sign_multiplier = -1 if change_sign == "-" or str(change_val).strip().startswith("-") else 1 + change_cl = re.sub(r'[\+\-,]', "", str(change_val)) + change_clean = float(change_cl) * change_sign_multiplier if pct_val == "N/A": - pct_val = float(0.0) # Bad data. FOund a filed with N/A instead of read num + pct_clean = float(0.0) # Bad data. FOund a filed with N/A instead of read num else: + pct_sign_multiplier = -1 if pct_sign == "-" or str(pct_val).strip().startswith("-") else 1 pct_cl = re.sub(r'[\%\+\-,]', "", pct_val ) - pct_clean = float(pct_cl) + pct_clean = float(pct_cl) * pct_sign_multiplier + if change_clean < 0 and pct_clean > 0: + pct_clean = -pct_clean ################################ 5 #################################### mktcap = (re.sub(r'[N\/A]', '0', mktcap)) # handle N/A diff --git a/y_topgainers.py b/y_topgainers.py index 7f48c8d..89f609e 100644 --- a/y_topgainers.py +++ b/y_topgainers.py @@ -178,13 +178,18 @@ def extr_gen(): co_name_lj = (re.sub(r'[\'\"]', '', co_name_lj) ) # remove " ' and strip leading/trailing spaces price_cl = (re.sub(r'\,', '', price)) # remove , price_clean = float(price_cl) - change_clean = float(change_val) + change_sign_multiplier = -1 if change_sign == "-" or str(change_val).strip().startswith("-") else 1 + change_cl = re.sub(r'[\+\-,]', "", str(change_val)) + change_clean = float(change_cl) * change_sign_multiplier if pct_val == "N/A": - pct_val = float(0.0) # Bad data. FOund a filed with N/A instead of read num + pct_clean = float(0.0) # Bad data. FOund a filed with N/A instead of read num else: + pct_sign_multiplier = -1 if pct_sign == "-" or str(pct_val).strip().startswith("-") else 1 pct_cl = re.sub(r'[\%\+\-,]', "", pct_val ) - pct_clean = float(pct_cl) + pct_clean = float(pct_cl) * pct_sign_multiplier + if change_clean < 0 and pct_clean > 0: + pct_clean = -pct_clean ################################ 5 #################################### mktcap = (re.sub(r'[N\/A]', '0', mktcap)) # handle N/A