Git Product home page Git Product logo

hipflights's Introduction

HipFlights: Hipmunk flights API coding exercise

Requirements

Requires Python. Tested on both python 2.7 and python 3.5.

3rd-party python deps (flask and requests) are handled by setup.py.

Installation and usage

Within a virtualenv of your choosing:

    git clone https://github.com/Badg/hipflights.git
    pip install -e ./hipflights
    python -m hipflights

Notes

  • Normally, I would version the API endpoint, for example using GET /flights/v1/search or GET /v1/flights/search, etc; since this would break the test script (not to mention violate the spec sheet!) I didn't.
  • This isn't really focused on scalability; I was more concerned with "shipping fast" and "write clean code". In a more perfect world, I would either mirror the scraperapi's use of tornado, or move to async/await in python 3
  • Furthermore, if I were really concerned about performance, I might set the whole thing up as a streaming system: read from each socket, parse each json result as you go, and merging on the fly, writing each result to the output socket immediately. The only problem there is you'd have to wait for all of the receiving sockets' buffers from the scrapers api call to have data, so if one of them went down, you might accumulate a bunch of junk in the socket buffers, potentially causing issues with backpressure (not to mention, effectively leaking memory)
  • I used heapq.merge to merge the sorted lists, rather than writing my own merge function, purely out of time constraints. Realistically speaking, I've seen benchmarks suggesting that it's actually fastest to .extend() and then .sort(), even when the input lists are sorted, for n < ~100000. This is a result of the list operations being written in C, whereas the heapq.merge call is implemented in pure Python
  • In a more perfect world, the API would implement some kind of pagination, instead of returning all results at once
  • This is geared towards simplicity; if you wanted to do anything more with the API than just merge results from different providers, I would very likely cast the parsed json into dedicated Result objects
  • (Hopefully obviously) in a production environment I would write more tests, particularly ones that do a better job of mocking the scraper APIs than simply running them locally. Given that the code exercise ships with its own test suite, and that the code is so simple, I instead opted to just test it locally several times.
  • I considered setting up Travis for this to make it easier to test against both python 2 and python 3, but it seemed like overkill, so I just tested it locally.

hipflights's People

Contributors

badg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.