cowsay-blog / .ipynb_checkpoints / deploy-checkpoint.ipynb

@ 483db1f38227ac6213d2d01259496367b15ea553 | history


{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import jinja2\n",
      "import os\n",
      "import arrow\n",
      "# PATH = os.path.dirname(os.path.realpath(__file__))\n",
      "PATH = os.getcwd()\n",
      "COWPOSTPATH = PATH + '/cowposts'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "ename": "ImportError",
       "evalue": "No module named arrow",
       "output_type": "pyerr",
       "traceback": [
        "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mImportError\u001b[0m                               Traceback (most recent call last)",
        "\u001b[0;32m<ipython-input-1-6799c4d0a12b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mjinja2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0marrow\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m \u001b[0;31m# PATH = os.path.dirname(os.path.realpath(__file__))\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0mPATH\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetcwd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
        "\u001b[0;31mImportError\u001b[0m: No module named arrow"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "template_loader = jinja2.FileSystemLoader(searchpath=PATH)\n",
      "template_env = jinja2.Environment(loader=templateLoader)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "ename": "NameError",
       "evalue": "name 'PATH' is not defined",
       "output_type": "pyerr",
       "traceback": [
        "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
        "\u001b[0;32m<ipython-input-4-da6f47bb9e95>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtemplate_loader\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjinja2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mFileSystemLoader\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msearchpath\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mPATH\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0mtemplate_env\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjinja2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mEnvironment\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mloader\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtemplateLoader\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
        "\u001b[0;31mNameError\u001b[0m: name 'PATH' is not defined"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "cowposts = []\n",
      "os.chdir(COWPOSTPATH)\n",
      "for cowpost in os.listdir(COWPOSTPATH):\n",
      "    with open(cowpost, 'r') as f:\n",
      "        cowposts.append(f.readlines())"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 29
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "cowposts"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 30,
       "text": [
        "[['Thu Nov  6 19:06:45 EST 2014\\n',\n",
        "  ' _____________________ \\n',\n",
        "  '< this is a test post >\\n',\n",
        "  ' --------------------- \\n',\n",
        "  '        \\\\   ^__^\\n',\n",
        "  '         \\\\  (oo)\\\\_______\\n',\n",
        "  '            (__)\\\\       )\\\\/\\\\\\n',\n",
        "  '                ||----w |\\n',\n",
        "  '                ||     ||\\n'],\n",
        " ['Thu Nov  6 19:14:58 EST 2014\\n',\n",
        "  ' ___________________________________ \\n',\n",
        "  '/ this is another test post $p3cI@L \\\\\\n',\n",
        "  '\\\\ ch@ract3r\\xc3\\xa7                       /\\n',\n",
        "  ' ----------------------------------- \\n',\n",
        "  '        \\\\   ^__^\\n',\n",
        "  '         \\\\  (oo)\\\\_______\\n',\n",
        "  '            (__)\\\\       )\\\\/\\\\\\n',\n",
        "  '                ||----w |\\n',\n",
        "  '                ||     ||\\n']]"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def dictify(cowlinelist):\n",
      "    cowdate = cowlinelist[0].strip()\n",
      "    cowtext = ''.join(cowlinelist[1:])\n",
      "    return {cowdate: cowtext}"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 31
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "cowdicts = [dictify(cowlines) for cowlines in cowposts]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 35
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def cowblogsort(cowdicts):\n",
      "    cowdates = [arrow.get(cowkey, 'ddd MMM D HH:mm:ss YYYY')\n",
      "                for cowkey in cowdicts]\n",
      "    return cowdates"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 36
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "cowblogsort(cowdicts)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "ename": "NameError",
       "evalue": "global name 'arrow' is not defined",
       "output_type": "pyerr",
       "traceback": [
        "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
        "\u001b[0;32m<ipython-input-37-bcdc109e08c4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcowblogsort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcowdicts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
        "\u001b[0;32m<ipython-input-36-9fefe0003d2d>\u001b[0m in \u001b[0;36mcowblogsort\u001b[0;34m(cowdicts)\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mcowblogsort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcowdicts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m     cowdates = [arrow.get(cowkey, 'ddd MMM D HH:mm:ss YYYY')\n\u001b[0;32m----> 3\u001b[0;31m                 for cowkey in cowdicts]\n\u001b[0m\u001b[1;32m      4\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0mcowdates\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
        "\u001b[0;31mNameError\u001b[0m: global name 'arrow' is not defined"
       ]
      }
     ],
     "prompt_number": 37
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}