From 8a74a79ac210d4e3ce98ec40edcc09a1bf19bb70 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Tue, 5 Dec 2017 15:17:03 +0100 Subject: [PATCH] Update doc link in README.md --- README.md | 14 +++++++++++++- flatisfy/data_files/__init__.py | 22 +++++++++++----------- flatisfy/models/flat.py | 7 +++---- flatisfy/web/routes/api.py | 19 ++++++++++--------- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 5806cae..a3aae16 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ Flatisfy Flatisfy is your new companion to ease your search of a new housing :) + + **Note**: This software is under heavy development at the moment, and the database schema could change at any time. Do not consider it as being @@ -36,6 +38,9 @@ This code is not restricted to handling flats only! See the [getting started guide](doc/0.getting_started.md). If you want to give it a try quickly, you can have a look at the [Docker image](doc/2.docker.md). +Documentation for the whole app is available +[online](https://doc.phyks.me/flatisfy/). + ## Documentation @@ -91,7 +96,14 @@ explicitly mentionned otherwise. See the `CONTRIBUTING.md` file for more infos. -## Support +## API + +Your Flatisfy instance is accessible through an API. API documentation is +available +[here](https://doc.phyks.me/flatisfy/flatisfy.web.routes.html#module-flatisfy.web.routes.api). + + +## Getting help Feel free to open issues. An IRC channel is available at [irc://irc.freenode.net/flatisfy](irc://irc.freenode.net/flatisfy) as well. diff --git a/flatisfy/data_files/__init__.py b/flatisfy/data_files/__init__.py index 36e31b8..a625485 100644 --- a/flatisfy/data_files/__init__.py +++ b/flatisfy/data_files/__init__.py @@ -18,6 +18,14 @@ from flatisfy.models.public_transport import PublicTransport LOGGER = logging.getLogger(__name__) MODULE_DIR = os.path.dirname(os.path.realpath(__file__)) +TRANSPORT_DATA_FILES = { + "FR-IDF": "stops_fr-idf.txt", + "FR-NW": "stops_fr-nw.txt", + "FR-NE": "stops_fr-ne.txt", + "FR-SW": "stops_fr-sw.txt", + "FR-SE": "stops_fr-se.txt" +} + def french_postal_codes_to_quarter(postal_code): """ @@ -129,18 +137,10 @@ def _preprocess_public_transport(): :return: A list of ``PublicTransport`` objects to be inserted in database. """ - DATA_FILES = { - "FR-IDF": "stops_fr-idf.txt", - "FR-NW": "stops_fr-nw.txt", - "FR-NE": "stops_fr-ne.txt", - "FR-SW": "stops_fr-sw.txt", - "FR-SE": "stops_fr-se.txt" - } - public_transport_data = [] # Load opendata file - for area, data_file in DATA_FILES.items(): - LOGGER.info("Building from public transport data %s." % data_file) + for area, data_file in TRANSPORT_DATA_FILES.items(): + LOGGER.info("Building from public transport data %s.", data_file) try: with io.open(os.path.join(MODULE_DIR, data_file), "r", encoding='utf-8') as fh: @@ -154,7 +154,7 @@ def _preprocess_public_transport(): lng=row[4] )) except (IOError, IndexError): - LOGGER.error("Invalid raw opendata file: %s." % data_file) + LOGGER.error("Invalid raw opendata file: %s.", data_file) return [] return public_transport_data diff --git a/flatisfy/models/flat.py b/flatisfy/models/flat.py index d683429..f7d6eb0 100644 --- a/flatisfy/models/flat.py +++ b/flatisfy/models/flat.py @@ -5,10 +5,10 @@ This modules defines an SQLAlchemy ORM model for a flat. # pylint: disable=locally-disabled,invalid-name,too-few-public-methods from __future__ import absolute_import, print_function, unicode_literals -import enum import logging import arrow +import enum from sqlalchemy import ( Column, DateTime, Enum, Float, SmallInteger, String, Text @@ -109,8 +109,7 @@ class Flat(BASE): return FlatUtilities.included elif utilities == "H.C.": return FlatUtilities.excluded - else: - return FlatUtilities.unknown + return FlatUtilities.unknown @validates("status") def validate_status(self, _, status): @@ -128,7 +127,7 @@ class Flat(BASE): return self.status.default.arg @validates("notation") - def validate_status(self, _, notation): + def validate_notation(self, _, notation): """ Notation validation method """ diff --git a/flatisfy/web/routes/api.py b/flatisfy/web/routes/api.py index 6a39ffb..11e565d 100644 --- a/flatisfy/web/routes/api.py +++ b/flatisfy/web/routes/api.py @@ -17,6 +17,8 @@ import flatisfy.data from flatisfy.models import flat as flat_model from flatisfy.models.postal_code import PostalCode +FILTER_RE = re.compile(r"filter\[([A-z0-9_]+)\]") + def JSONError(error_code, error_str): """ @@ -105,7 +107,6 @@ def flats_v1(config, db): db_query = db.query(flat_model.Flat) # Handle filtering according to JSON API spec - FILTER_RE = re.compile(r"filter\[([A-z0-9_]+)\]") filters = {} for param in bottle.request.query: filter_match = FILTER_RE.match(param) @@ -124,7 +125,7 @@ def flats_v1(config, db): return { "data": flats } - except Exception as exc: + except Exception as exc: # pylint: disable= broad-except return JSONError(500, str(exc)) @@ -147,7 +148,7 @@ def flat_v1(flat_id, config, db): return { "data": _serialize_flat(flat, config) } - except Exception as exc: + except Exception as exc: # pylint: disable= broad-except return JSONError(500, str(exc)) @@ -177,8 +178,8 @@ def update_flat_v1(flat_id, config, db): try: json_body = json.load(bottle.request.body) - for k, v in json_body.items(): - setattr(flat, k, v) + for key, value in json_body.items(): + setattr(flat, key, value) except ValueError as exc: return JSONError( 400, @@ -188,7 +189,7 @@ def update_flat_v1(flat_id, config, db): return { "data": _serialize_flat(flat, config) } - except Exception as exc: + except Exception as exc: # pylint: disable= broad-except return JSONError(500, str(exc)) @@ -213,7 +214,7 @@ def time_to_places_v1(config): return { "data": places } - except Exception as exc: + except Exception as exc: # pylint: disable= broad-except return JSONError(500, str(exc)) @@ -245,7 +246,7 @@ def search_v1(db, config): return { "data": flats } - except Exception as exc: + except Exception as exc: # pylint: disable= broad-except return JSONError(500, str(exc)) @@ -284,7 +285,7 @@ def ics_feed_v1(config, db): description += '\n{}\n'.format(flat.notes) vevent.add('description').value = description - except: + except Exception: # pylint: disable= broad-except pass return cal.serialize()