Skip to content

Instantly share code, notes, and snippets.

@Phaeilo
Created July 23, 2013 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Phaeilo/6061479 to your computer and use it in GitHub Desktop.
Save Phaeilo/6061479 to your computer and use it in GitHub Desktop.
Script to plot all samples in the database of the Wigle Wifi app.
#!/usr/bin/env python
# The MIT License (MIT)
#
# Copyright (c) 2013 Philip Huppert
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
PlotWigleWifi.py:
Command line utility to plot all samples recorded by the Wifle Wifi app.
"""
__author__ = "Philip Huppert"
__copyright__ = "Copyright 2013, Philip Huppert"
__license__ = "MIT"
__version__ = "1.0"
import sys
import os
import math
import sqlite3
try:
import numpy as np
except ImportError:
raise Exception("Please install numpy! (http://numpy.org)")
try:
import matplotlib.pyplot as plt
except ImportError:
raise Exception("Please install matplotlib! (http://matplotlib.org/)")
FILENAME = "wiglewifi.sqlite"
def printe(line):
sys.stderr.write(line + "\n")
def main():
filename = FILENAME if len(sys.argv) < 2 else sys.argv[1]
if not os.path.exists(filename):
script = os.path.basename(sys.argv[0])
printe("usage: %s <database>" % script)
printe(" database: Sqlite database from the Wigle Wifi app")
sys.exit(1)
# Fetch wifi samples from database:
conn = sqlite3.connect(filename)
c = conn.cursor()
c.execute("select lat,lon from location where time > 0")
lats = []
lons = []
# Build lists of lats and lons for plotting:
for row in c:
lat, lon = row
lats.append(float(lat))
lons.append(float(lon))
conn.close()
# Plot samples:
plt.xlabel("Longitude")
plt.ylabel("Latitude")
plt.title("Received Wifis")
plt.plot(lons, lats, marker=".", linestyle="None")
plt.show()
sys.exit(0)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment