Coder Social home page Coder Social logo

paulgoetze / elixir-python Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 2.0 1.09 MB

Examples for running Python code from Elixir

Home Page: http://paulgoetze.com/2017/04/19/building-a-city-search-with-elixir-and-python

Elixir 52.34% Python 47.66%
elixir python whoosh erlport search-in-text geolite2

elixir-python's Introduction

Examples for using Python with Elixir

The GeoLite2 example app use erlport via export in order to leverage the Whoosh text indexing and search Python package.

It creates a search index from the free GeoLite2 city database and provides an Elixir module to search the city index.

Installation

  • Install Python v3.x
  • Install Elixir v1.4+
  • Setup a virtualenv and activate it
  • Run pip install -r requirements.txt to install the python dependencies
  • Run mix deps.get to install the Hex dependencies

Creating the index

Step into the interactive Elixir console with iex -S mix.

Then run the following function to create the city index:

ElixirPython.GeoLite2.create_index()

Searching

You can search your city index with the following code:

iex(1)> ElixirPython.GeoLite2.search("Berlin")
[%{city: "Berlin", country: "Germany", state: "Land Berlin"},
 %{city: "Berlingen", country: "Belgium", state: "Flanders"},
 %{city: "Falkenberg", country: "Germany", state: "Land Berlin"},
 %{city: "Gosen", country: "Germany", state: "Land Berlin"},
 %{city: "Bernau bei Berlin", country: "Germany", state: "Brandenburg"},
 %{city: "Berlingen", country: "Switzerland", state: "Thurgau"},
 %{city: "Treptow Bezirk", country: "Germany", state: "Land Berlin"},
 %{city: "Heinersdorf", country: "Germany", state: "Land Berlin"},
 %{city: "Stirling", country: "Canada", state: "Alberta"},
 %{city: "New Berlin", country: "United States", state: "Illinois"}]

The default number of returned results is 10.
You can also pass the number of wanted results as the second argument:

iex(2)> ElixirPython.GeoLite2.search("Berlin", 3)
[%{city: "Berlin", country: "Germany", state: "Land Berlin"},
 %{city: "Berlingen", country: "Belgium", state: "Flanders"},
 %{city: "Falkenberg", country: "Germany", state: "Land Berlin"}]

elixir-python's People

Contributors

paulgoetze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

okadath mohithg

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.