Fix Decimal issue with JSON
This commit is contained in:
parent
847a5954d5
commit
65bd5db98a
@ -9,7 +9,6 @@ import collections
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
|
|
||||||
import flatisfy.exceptions
|
import flatisfy.exceptions
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import itertools
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from flatisfy import data
|
|
||||||
from flatisfy import tools
|
from flatisfy import tools
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
@ -38,6 +37,22 @@ class WeboobProxy(object):
|
|||||||
"""
|
"""
|
||||||
return WebNip.VERSION
|
return WebNip.VERSION
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def restore_decimal_fields(flat):
|
||||||
|
"""
|
||||||
|
Parse fields expected to be in Decimal type to float. They were dumped
|
||||||
|
as str in the JSON dump process.
|
||||||
|
|
||||||
|
:param flat: A flat dict.
|
||||||
|
:return: A flat dict with Decimal fields converted to float.
|
||||||
|
"""
|
||||||
|
for field in ["area", "cost", "rooms", "bedrooms", "price_per_meter"]:
|
||||||
|
try:
|
||||||
|
flat[field] = float(flat[field])
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
flat[field] = None
|
||||||
|
return flat
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
"""
|
"""
|
||||||
Create a Weboob handle and try to load the modules.
|
Create a Weboob handle and try to load the modules.
|
||||||
@ -177,6 +192,8 @@ def fetch_flats_list(config):
|
|||||||
LOGGER.info("Fetched %d flats.", len(housing_posts))
|
LOGGER.info("Fetched %d flats.", len(housing_posts))
|
||||||
|
|
||||||
flats_list = [json.loads(flat) for flat in housing_posts]
|
flats_list = [json.loads(flat) for flat in housing_posts]
|
||||||
|
flats_list = [WeboobProxy.restore_decimal_fields(flat)
|
||||||
|
for flat in flats_list]
|
||||||
return flats_list
|
return flats_list
|
||||||
|
|
||||||
|
|
||||||
@ -193,6 +210,7 @@ def fetch_details(config, flat_id):
|
|||||||
weboob_output = weboob_proxy.info(flat_id)
|
weboob_output = weboob_proxy.info(flat_id)
|
||||||
|
|
||||||
flat_details = json.loads(weboob_output)
|
flat_details = json.loads(weboob_output)
|
||||||
|
flats_details = WeboobProxy.restore_decimal_fields(flat_details)
|
||||||
LOGGER.info("Fetched details for flat %s.", flat_id)
|
LOGGER.info("Fetched details for flat %s.", flat_id)
|
||||||
|
|
||||||
return flat_details
|
return flat_details
|
||||||
|
@ -34,6 +34,7 @@ def init(flats_list):
|
|||||||
flat["urls"] = [flat["url"]]
|
flat["urls"] = [flat["url"]]
|
||||||
# Create merged_ids key
|
# Create merged_ids key
|
||||||
flat["merged_ids"] = [flat["id"]]
|
flat["merged_ids"] = [flat["id"]]
|
||||||
|
|
||||||
return flats_list
|
return flats_list
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class ConfigPlugin(object):
|
|||||||
"""
|
"""
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
def setup(self, app): # pylint: disable=no-self-use
|
def setup(self, app): # pylint: disable=locally-disabled,no-self-use
|
||||||
"""
|
"""
|
||||||
Make sure that other installed plugins don't affect the same
|
Make sure that other installed plugins don't affect the same
|
||||||
keyword argument and check if metadata is available.
|
keyword argument and check if metadata is available.
|
||||||
|
@ -11,7 +11,6 @@ from __future__ import (
|
|||||||
absolute_import, division, print_function, unicode_literals
|
absolute_import, division, print_function, unicode_literals
|
||||||
)
|
)
|
||||||
|
|
||||||
import functools
|
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
import bottle
|
import bottle
|
||||||
@ -33,7 +32,7 @@ class DatabasePlugin(object):
|
|||||||
"""
|
"""
|
||||||
self.get_session = get_session
|
self.get_session = get_session
|
||||||
|
|
||||||
def setup(self, app): # pylint: disable=no-self-use
|
def setup(self, app): # pylint: disable=locally-disabled,no-self-use
|
||||||
"""
|
"""
|
||||||
Make sure that other installed plugins don't affect the same
|
Make sure that other installed plugins don't affect the same
|
||||||
keyword argument and check if metadata is available.
|
keyword argument and check if metadata is available.
|
||||||
|
@ -197,7 +197,7 @@ export default {
|
|||||||
},
|
},
|
||||||
displayedStations () {
|
displayedStations () {
|
||||||
if (this.flat.flatisfy_stations.length > 0) {
|
if (this.flat.flatisfy_stations.length > 0) {
|
||||||
const stationsNames = this.flat.flatisfy_stations.map(station => station.name)
|
const stationsNames = this.flat.flatisfy_stations.map(station => capitalize(station.name))
|
||||||
return stationsNames.join(', ')
|
return stationsNames.join(', ')
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
|
Loading…
Reference in New Issue
Block a user