Commit 9fa3bfe

bryfry <bryon.fryer@gmail.com>
2014-02-17 22:55:54
start notebook
1 parent 22185b2
Changed files (1)
atarg/atarg.ipynb
@@ -0,0 +1,186 @@
+{
+ "metadata": {
+  "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+  {
+   "cells": [
+    {
+     "cell_type": "markdown",
+     "metadata": {},
+     "source": [
+      "# ATARG\n",
+      "\n",
+      "### Config.py (example)"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "MYSQL_USER = \"admin\"\n",
+      "MYSQL_PASS = \"docker\"\n",
+      "MYSQL_ADDR = \"192.168.32.237\"\n",
+      "MYSQL_DB   = \"test\"\n",
+      "ALCHEMY_ECHO = False"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 15
+    },
+    {
+     "cell_type": "heading",
+     "level": 3,
+     "metadata": {},
+     "source": [
+      "Test sqlalchemy connection"
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "# requires sqlalchemy, mysql-python\n",
+      "from sqlalchemy import create_engine\n",
+      "from sqlalchemy.ext.declarative import declarative_base\n",
+      "from sqlalchemy import Column, Integer, String, Enum, Date\n",
+      "\n",
+      "engine = create_engine('mysql://%s:%s@%s/%s' % (\n",
+      "                       MYSQL_USER, \n",
+      "                       MYSQL_PASS, \n",
+      "                       MYSQL_ADDR,\n",
+      "                       MYSQL_DB), echo=ALCHEMY_ECHO)\n",
+      "Base = declarative_base()\n",
+      "\n",
+      "class Appointment(Base):\n",
+      "  __tablename__ = 'appointments'\n",
+      "  id         = Column(Integer, primary_key=True)\n",
+      "  visitor    = Column(String(7))\n",
+      "  submitter  = Column(String(7))\n",
+      "  start_date = Column(Date) \n",
+      "  end_date   = Column(Date)\n",
+      "  location   = Column(Enum('upstairs', 'downstiars', name=\"loacation_type\"))\n",
+      "  status     = Column(Enum('verifed', 'needs tickets', 'needs pnpi', name=\"status_type\"))\n",
+      "\n",
+      "  def __init__(self, visitor, submitter, start_date, end_date, location, status):\n",
+      "    self.visitor = visitor\n",
+      "    self.submitter = submitter\n",
+      "    self.start_date = start_date\n",
+      "    self.end_date = end_date\n",
+      "    self.location = location\n",
+      "    self.status = status\n",
+      "\n",
+      "Base.metadata.create_all(engine)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 20
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "from sqlalchemy.orm import sessionmaker\n",
+      "Session = sessionmaker(bind=engine)\n",
+      "session = Session()"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 21
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "test_appt = Appointment(visitor='vis', \n",
+      "             submitter='sub', \n",
+      "             start_date=0, \n",
+      "             end_date=0, \n",
+      "             location='upstairs',\n",
+      "             status='verified')"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 22
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "session.add(test_appt)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 27
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "appt_test = session.query(Appointment).filter_by(location='upstairs')"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [],
+     "prompt_number": 52
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "for i in appt_test:\n",
+      "    print i.visitor"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "output_type": "stream",
+       "stream": "stdout",
+       "text": [
+        "vis\n"
+       ]
+      }
+     ],
+     "prompt_number": 56
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "result"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 35,
+       "text": [
+        "<sqlalchemy.orm.query.Query at 0x10740f110>"
+       ]
+      }
+     ],
+     "prompt_number": 35
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [],
+     "language": "python",
+     "metadata": {},
+     "outputs": []
+    }
+   ],
+   "metadata": {}
+  }
+ ]
+}
\ No newline at end of file