Commits

Steve Losh committed 66bbd0f

assorted changes

Comments (0)

Files changed (16)

omw.py

-from flask import Flask
-app = Flask(__name__)
-
-from flask import render_template
-
-@app.route('/')
-def hello_world():
-    return render_template('index.html')
-
-if __name__ == '__main__':
-    from flaskext.lesscss import lesscss
-    lesscss(app)
-
-    app.debug = True
-    app.run()
-

omw/__init__.py

Empty file added.
+try:
+    import json
+except ImportError:
+    import simplejson as json
+
+from flask import Flask
+app = Flask(__name__)
+
+from flask import abort, render_template, request
+
+import redis
+r = redis.Redis(host='localhost')
+
+from util import new_id
+
+@app.route('/')
+def hello_world():
+    return render_template('index.html')
+
+@app.route('/trip/<tid>/')
+def trip(tid):
+    trip = r.hgetall('trip:%s' % tid)
+    if not trip:
+        abort(404)
+    return render_template('trip.html', trip=trip)
+
+
+@app.route('/api/trip/', methods=['POST'])
+def api_trip():
+    tid = new_id()
+    r.hset('trip:%s' % tid, 'description', request.json['description'])
+    return json.dumps({'status': 'OK', 'tid': tid})
+
+@app.route('/api/trip/<tid>/locs/', methods=['GET', 'POST'])
+def api_trip_locs(tid):
+    locs = r.zrevrange('trip:%s:locs' % tid, 0, 1)
+    return json.dumps(list(reversed(locs)))
+
+
+@app.route('/api/trip/<tid>/')
+def api_trip_get(tid):
+    pass
+
+
+if __name__ == '__main__':
+    from flaskext.lesscss import lesscss
+    lesscss(app)
+
+    app.debug = True
+    app.run()
+

omw/static/aal.css

+/* 
+  aardvark.legs by Anatoli Papirovski - http://fecklessmind.com/
+  Licensed under the MIT license. http://www.opensource.org/licenses/mit-license.php
+*/
+
+/* 
+  Reset first. Modified version of Eric Meyer and Paul Chaplin reset 
+  from http://meyerweb.com/eric/tools/css/reset/ 
+*/
+html, body, div, span, applet, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, big, cite, code,
+del, dfn, em, font, img, ins, kbd, q, s, samp,
+small, strike, strong, sub, sup, tt, var,
+b, u, i, center,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td,
+header, nav, section, article, aside, footer
+{border: 0; margin: 0; outline: 0; padding: 0; background: transparent; vertical-align: baseline;}
+
+blockquote, q {quotes: none;}
+blockquote:before,blockquote:after,q:before,q:after {content: ''; content: none;}
+
+header, nav, section, article, aside, footer {display: block;}
+
+/* Basic styles */
+body {background: #fff; color: #000; font: 1em/1.5em Helvetica, Arial, "Liberation Sans", "Bitstream Vera Sans", sans-serif;}
+html>body {font-size: 16px;}
+
+img {display: inline-block; vertical-align: bottom;}
+
+h1,h2,h3,h4,h5,h6,strong,b,dt,th {font-weight: 700;}
+address,cite,em,i,caption,dfn,var {font-style: italic;}
+
+h1 {margin: 0 0 0.75em; font-size: 2em;}
+h2 {margin: 0 0 1em; font-size: 1.5em;}
+h3 {margin: 0 0 1.286em; font-size: 1.167em;}
+h4 {margin: 0 0 1.5em; font-size: 1em;}
+h5 {margin: 0 0 1.8em; font-size: .834em;}
+h6 {margin: 0 0 2em; font-size: .75em;}
+
+p,ul,ol,dl,blockquote,pre {margin: 0 0 1.5em;}
+
+li ul,li ol {margin: 0;}
+ul {list-style: outside disc;}
+ol {list-style: outside decimal;}
+li {margin: 0 0 0 2em;}
+dd {padding-left: 1.5em;}
+blockquote {padding: 0 1.5em;}
+
+a {text-decoration: underline;}
+a:hover {text-decoration: none;}
+abbr,acronym {border-bottom: 1px dotted; cursor: help;}
+del {text-decoration: line-through;}
+ins {text-decoration: overline;}
+sub {font-size: .834em; line-height: 1em; vertical-align: sub;}
+sup {font-size: .834em; line-height: 1em; vertical-align: super;}
+
+tt,code,kbd,samp,pre {font-size: 1em; font-family: "Courier New", Courier, monospace;}
+
+/* Table styles */
+table {border-collapse: collapse; border-spacing: 0; margin: 0 0 1.5em;}
+caption {text-align: left;}
+th, td {padding: .25em .5em;}
+tbody td, tbody th {border: 1px solid #000;}
+tfoot {font-style: italic;}
+
+/* Form styles */
+fieldset {clear: both;}
+legend {padding: 0 0 1.286em; font-size: 1.167em; font-weight: 700;}
+fieldset fieldset legend {padding: 0 0 1.5em; font-size: 1em;}
+* html legend {margin-left: -7px;}
+*+html legend {margin-left: -7px;}
+
+form .field, form .buttons {clear: both; margin: 0 0 1.5em;}
+form .field label {display: block;}
+form ul.fields li {list-style-type: none; margin: 0;}
+form ul.inline li, form ul.inline label {display: inline;}
+form ul.inline li {padding: 0 .75em 0 0;}
+
+input.radio, input.checkbox {vertical-align: top;}
+label, button, input.submit, input.image {cursor: pointer;}
+* html input.radio, * html input.checkbox {vertical-align: middle;}
+*+html input.radio, *+html input.checkbox {vertical-align: middle;}
+
+textarea {overflow: auto;}
+input.text, input.password, textarea, select {margin: 0; font: 1em/1.3 Helvetica, Arial, "Liberation Sans", "Bitstream Vera Sans", sans-serif; vertical-align: baseline;}
+input.text, input.password, textarea {border: 1px solid #444; border-bottom-color: #666; border-right-color: #666; padding: 2px;}
+
+* html button {margin: 0 .34em 0 0;}
+*+html button {margin: 0 .34em 0 0;}
+
+form.horizontal .field {padding-left: 150px;}
+form.horizontal .field label {display: inline; float: left; width: 140px; margin-left: -150px;}
+
+/* Useful classes */
+img.left {display: inline; float: left; margin: 0 1.5em .75em 0;}
+img.right {display: inline; float: right; margin: 0 0 .75em .75em;}

omw/static/style.css

+html {
+  overflow-y: scroll;
+}
+html, body {
+  background-color: #a69055;
+}
+body .wrap {
+  width: 800px;
+  margin: 0 auto;
+}
+body .title {
+  text-align: center;
+  font-size: 4em;
+  margin-top: 0.75em;
+  margin-bottom: 0.375em;
+  font-weight: bold;
+  color: #211d11;
+  text-shadow: #c1b186 0px 1px 1px;
+}
+body .footer {
+  font-style: italic;
+  text-align: center;
+  margin-top: 1.5em;
+}
+body .footer a {
+  color: #2d2b21;
+  text-decoration: none;
+}
+body .footer a:hover {
+  text-decoration: underline;
+}
+body .content {
+  background-color: white;
+  padding: 20px;
+  -webkit-border-radius: 4px;
+  -moz-border-radius: 4px;
+  border-radius: 4px;
+}
+.trip #map_canvas {
+  width: 760px;
+  height: 500px;
+  border: 1px solid #a69055;
+}

omw/static/style.less

+@c-black: #141919;
+@c-grey: #2D2B21;
+@c-brown: #A69055;
+@c-tan: #C9B086;
+@c-white: #FFF8ED;
+
+@body-width: 800px;
+@body-padding: 20px;
+
+
+.border-radius(@size: 4px) {
+    -webkit-border-radius: @size;
+    -moz-border-radius: @size;
+    border-radius: @size;
+}
+
+html {
+    overflow-y: scroll;
+}
+html, body {
+    background-color: @c-brown;
+}
+
+body {
+    .wrap {
+        width: @body-width;
+        margin: 0 auto;
+    }
+    .title {
+        text-align: center;
+        font-size: 4em;
+        margin-top: 0.75em;
+        margin-bottom: 0.375em;
+        font-weight: bold;
+        color: darken(@c-brown, 80%);
+        text-shadow: lighten(@c-brown, 30%) 0px 1px 1px;
+    }
+    .footer {
+        font-style: italic;
+        text-align: center;
+        margin-top: 1.5em;
+
+        a {
+            color: @c-grey;
+            text-decoration: none;
+
+            &:hover {
+                text-decoration: underline;
+            }
+        }
+    }
+    .content {
+        background-color: white;
+        padding: @body-padding;
+
+        .border-radius(4px);
+    }
+}
+
+.trip {
+    #map_canvas {
+        width: (@body-width - (2 * @body-padding));
+        height: 500px;
+        border: 1px solid @c-brown;
+    }
+}

omw/templates/base.html

+<!DOCTYPE html>
+<html>
+    <head>
+        <title>On My Way!</title>
+        <link type="text/css" rel="stylesheet" href="/static/aal.css" />
+        <link type="text/css" rel="stylesheet" href="/static/style.css" />
+
+        {% block head %}{% endblock %}
+    </head>
+
+    <body class="{% block id %}{% endblock %}" onload="{% block onload %}{% endblock %}">
+        <div class="wrap">
+            <div class="title">On My Way!</div>
+            <div class="content">
+                {% block content %}{% endblock %}
+            </div>
+            <div class="footer">
+                Made by <a href="http://stevelosh.com">Steve</a>.
+            </div>
+        </div>
+    </body>
+</html>

omw/templates/index.html

+{% extends "base.html" %}
+
+{% block content %}
+    <p>Find your friends.</p>
+{% endblock %}

omw/templates/trip.html

+{% extends "base.html" %}
+{% block id %}trip{% endblock %}
+
+{% block head %}
+    <script type="text/javascript"
+            src="http://maps.google.com/maps/api/js?sensor=false">
+    </script>
+
+    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
+
+    <style type="text/css">
+      html { height: 100% }
+      body { height: 100%; margin: 0px; padding: 0px }
+      #map_canvas { height: 100% }
+    </style>
+
+    <script type="text/javascript">
+      function initialize() {
+        var latlng = new google.maps.LatLng(-34.397, 150.644);
+        var myOptions = {
+          zoom: 8,
+          center: latlng,
+          mapTypeId: google.maps.MapTypeId.ROADMAP
+        };
+        var map = new google.maps.Map(document.getElementById("map_canvas"),
+            myOptions);
+      }
+
+    </script>
+{% endblock %}
+
+{% block onload %}initialize(){% endblock %}
+
+{% block content %}
+    <p>{{ trip['description'] }}</p>
+    <div id="map_canvas">Fuck</div>
+{% endblock %}
+import random
+import redis
+
+GOOD_CHARACTERS = 'abcdefghjkmnpqrstuvwxyz23456789'
+r = redis.Redis(host='localhost')
+
+def random_id(length=4):
+    return ''.join(random.choice(GOOD_CHARACTERS) for _ in range(length))
+
+def new_id(length=4):
+    while True:
+        tid = random_id(length)
+        if not r.exists(tid):
+            return tid
+
 -e git+http://github.com/mitsuhiko/flask.git#egg=flask
 -e hg+http://bitbucket.org/sjl/flask-lesscss#egg=flask-lesscss
 
+# Redis
+-e git+http://github.com/andymccurdy/redis-py.git#egg=redis

static/aal.css

-/* 
-  aardvark.legs by Anatoli Papirovski - http://fecklessmind.com/
-  Licensed under the MIT license. http://www.opensource.org/licenses/mit-license.php
-*/
-
-/* 
-  Reset first. Modified version of Eric Meyer and Paul Chaplin reset 
-  from http://meyerweb.com/eric/tools/css/reset/ 
-*/
-html, body, div, span, applet, object, iframe,
-h1, h2, h3, h4, h5, h6, p, blockquote, pre,
-a, abbr, acronym, address, big, cite, code,
-del, dfn, em, font, img, ins, kbd, q, s, samp,
-small, strike, strong, sub, sup, tt, var,
-b, u, i, center,
-dl, dt, dd, ol, ul, li,
-fieldset, form, label, legend,
-table, caption, tbody, tfoot, thead, tr, th, td,
-header, nav, section, article, aside, footer
-{border: 0; margin: 0; outline: 0; padding: 0; background: transparent; vertical-align: baseline;}
-
-blockquote, q {quotes: none;}
-blockquote:before,blockquote:after,q:before,q:after {content: ''; content: none;}
-
-header, nav, section, article, aside, footer {display: block;}
-
-/* Basic styles */
-body {background: #fff; color: #000; font: 1em/1.5em Helvetica, Arial, "Liberation Sans", "Bitstream Vera Sans", sans-serif;}
-html>body {font-size: 16px;}
-
-img {display: inline-block; vertical-align: bottom;}
-
-h1,h2,h3,h4,h5,h6,strong,b,dt,th {font-weight: 700;}
-address,cite,em,i,caption,dfn,var {font-style: italic;}
-
-h1 {margin: 0 0 0.75em; font-size: 2em;}
-h2 {margin: 0 0 1em; font-size: 1.5em;}
-h3 {margin: 0 0 1.286em; font-size: 1.167em;}
-h4 {margin: 0 0 1.5em; font-size: 1em;}
-h5 {margin: 0 0 1.8em; font-size: .834em;}
-h6 {margin: 0 0 2em; font-size: .75em;}
-
-p,ul,ol,dl,blockquote,pre {margin: 0 0 1.5em;}
-
-li ul,li ol {margin: 0;}
-ul {list-style: outside disc;}
-ol {list-style: outside decimal;}
-li {margin: 0 0 0 2em;}
-dd {padding-left: 1.5em;}
-blockquote {padding: 0 1.5em;}
-
-a {text-decoration: underline;}
-a:hover {text-decoration: none;}
-abbr,acronym {border-bottom: 1px dotted; cursor: help;}
-del {text-decoration: line-through;}
-ins {text-decoration: overline;}
-sub {font-size: .834em; line-height: 1em; vertical-align: sub;}
-sup {font-size: .834em; line-height: 1em; vertical-align: super;}
-
-tt,code,kbd,samp,pre {font-size: 1em; font-family: "Courier New", Courier, monospace;}
-
-/* Table styles */
-table {border-collapse: collapse; border-spacing: 0; margin: 0 0 1.5em;}
-caption {text-align: left;}
-th, td {padding: .25em .5em;}
-tbody td, tbody th {border: 1px solid #000;}
-tfoot {font-style: italic;}
-
-/* Form styles */
-fieldset {clear: both;}
-legend {padding: 0 0 1.286em; font-size: 1.167em; font-weight: 700;}
-fieldset fieldset legend {padding: 0 0 1.5em; font-size: 1em;}
-* html legend {margin-left: -7px;}
-*+html legend {margin-left: -7px;}
-
-form .field, form .buttons {clear: both; margin: 0 0 1.5em;}
-form .field label {display: block;}
-form ul.fields li {list-style-type: none; margin: 0;}
-form ul.inline li, form ul.inline label {display: inline;}
-form ul.inline li {padding: 0 .75em 0 0;}
-
-input.radio, input.checkbox {vertical-align: top;}
-label, button, input.submit, input.image {cursor: pointer;}
-* html input.radio, * html input.checkbox {vertical-align: middle;}
-*+html input.radio, *+html input.checkbox {vertical-align: middle;}
-
-textarea {overflow: auto;}
-input.text, input.password, textarea, select {margin: 0; font: 1em/1.3 Helvetica, Arial, "Liberation Sans", "Bitstream Vera Sans", sans-serif; vertical-align: baseline;}
-input.text, input.password, textarea {border: 1px solid #444; border-bottom-color: #666; border-right-color: #666; padding: 2px;}
-
-* html button {margin: 0 .34em 0 0;}
-*+html button {margin: 0 .34em 0 0;}
-
-form.horizontal .field {padding-left: 150px;}
-form.horizontal .field label {display: inline; float: left; width: 140px; margin-left: -150px;}
-
-/* Useful classes */
-img.left {display: inline; float: left; margin: 0 1.5em .75em 0;}
-img.right {display: inline; float: right; margin: 0 0 .75em .75em;}

static/style.css

-html {
-  overflow-y: scroll;
-}
-html, body {
-  background-color: #a69055;
-}
-body .wrap {
-  width: 800px;
-  margin: 0 auto;
-}
-body .title {
-  text-align: center;
-  font-size: 4em;
-  margin-top: 0.75em;
-  margin-bottom: 0.375em;
-  font-weight: bold;
-  color: #211d11;
-  text-shadow: #c1b186 0px 1px 1px;
-}
-body .footer {
-  font-style: italic;
-  text-align: center;
-  margin-top: 1.5em;
-}
-body .footer a {
-  color: #2d2b21;
-  text-decoration: none;
-}
-body .footer a:hover {
-  text-decoration: underline;
-}
-body .content {
-  background-color: white;
-  padding: 20px;
-  -webkit-border-radius: 4px;
-  -moz-border-radius: 4px;
-  border-radius: 4px;
-}

static/style.less

-@c-black: #141919;
-@c-grey: #2D2B21;
-@c-brown: #A69055;
-@c-tan: #C9B086;
-@c-white: #FFF8ED;
-
-@body-width: 800px;
-
-
-.border-radius(@size: 4px) {
-    -webkit-border-radius: @size;
-    -moz-border-radius: @size;
-    border-radius: @size;
-}
-
-html {
-    overflow-y: scroll;
-}
-html, body {
-    background-color: @c-brown;
-}
-
-body {
-    .wrap {
-        width: @body-width;
-        margin: 0 auto;
-    }
-    .title {
-        text-align: center;
-        font-size: 4em;
-        margin-top: 0.75em;
-        margin-bottom: 0.375em;
-        font-weight: bold;
-        color: darken(@c-brown, 80%);
-        text-shadow: lighten(@c-brown, 30%) 0px 1px 1px;
-    }
-    .footer {
-        font-style: italic;
-        text-align: center;
-        margin-top: 1.5em;
-
-        a {
-            color: @c-grey;
-            text-decoration: none;
-
-            &:hover {
-                text-decoration: underline;
-            }
-        }
-    }
-    .content {
-        background-color: white;
-        padding: 20px;
-
-        .border-radius(4px);
-    }
-}

templates/base.html

-<!DOCTYPE html>
-<html>
-    <head>
-        <title>On My Way!</title>
-        <link type="text/css" rel="stylesheet" href="/static/aal.css" />
-        <link type="text/css" rel="stylesheet" href="/static/style.css" />
-    </head>
-
-    <body>
-        <div class="wrap">
-            <div class="title">On My Way!</div>
-            <div class="content">
-                {% block content %}{% endblock %}
-            </div>
-            <div class="footer">
-                Made by <a href="http://stevelosh.com">Steve</a>.
-            </div>
-        </div>
-    </body>
-</html>

templates/index.html

-{% extends "base.html" %}
-
-{% block content %}
-    <p>Find your friends.</p>
-{% endblock %}