cowsay-blog

commit f7e2be4be7fc284e6a501d2a83b4889e7d923add

tree

parent:
6ecd3cfcc21db364702307bc045644ae3b4c3eb5

Nick Mykins <nick.mykins@gmail.com>

2015-01-19T16:39:44-05:00

use sqlite

diff --git a/README.md b/README.md
index e7eebc9a3a3409f3065b7fe98b3aec773908993c..3c32002ba4db2aea92eeab76135084247c349f0e 100644
--- a/README.md
+++ b/README.md
@@ -5,10 +5,10 @@     
     # Use your favorite editor to make deploy scp to the right place
     vi deploy
     
-    # Make necessary directories
-    mkdir posts cowposts cowposts_html
+    # Make necessary directory for index
+    mkdir cowposts_html
     
     # Moo!
     echo "hello world" > hello_world
-    . cowpost hello_world
+    python cowpost.py hello_world
     . deploy
diff --git a/cowtemplate.html b/cowtemplate.html
index b9d249879837a3b39e3829a172aaa253dd48451a..1c6acaf5a617d553328e355ea08d70332af4f5a2 100644
--- a/cowtemplate.html
+++ b/cowtemplate.html
@@ -5,7 +5,7 @@   </head>
   <body>
     <link rel="stylesheet" type="text/css" href="style.css">
     <h1>~ nick's page ~</h1>
-    <h2>Optimized for 800x600 -- Welcome to the farm.<br><br>You know when you talk to God as a kid, but then you realize that what you were trying to convince yourself was God responding to your prayers was just more of your own internal monologue? I do.</h2>
+    <h2>Optimized for 800x600<br><br>You know when you talk to God as a kid, but then you realize that what you were trying to convince yourself was God responding to your prayers was just more of your own internal monologue? I do.</h2>
     <div>
         <div style="float:left">
 {% for cowpost in cowposts %}<pre>
@@ -28,16 +28,11 @@          \  (##)\_______
             (__)\       )\/\
                 ||----w |
    <font color=green>\|/</font>          ||     ||
-
-    echo "I'm free" |
-         cowsay -d  |
-       cowthink -n
              </pre>
             <h2>Here's some other stuff:</h2>
             <ul>
                 <li><a href="http://lt-dan.tumblr.com">Lieutenant Dan</a>
                 <li><a href="http://fart.town:5000">Random Java class name</a>
-                <li><a href="http://comics-jam.tumblr.com">Comics Jam</a>
                 <li><a href="http://github.com/nmyk/cowsay-blog">Cowsay blog on github</a>
             </ul>
             <br>
diff --git a/deploy b/deploy
index 23f00daa5f26fa8fef99cf46eadb2ddedadc9522..159b3e5effdea2f2c3c77c890291b0297ffdd5f3 100755
--- a/deploy
+++ b/deploy
@@ -1,5 +1,5 @@
 #!/bin/bash
 
 python deploy.py
-scp public_html/index.html public_html/style.css nick@nickmykins.com:~/public_html/
-scp cowposts_html/*.html nick@nickmykins.com:~/public_html/cowposts/
+scp public_html/index.html public_html/style.css nick.com:/var/www/cowsay-blog
+scp cowposts_html/*.html nick.com:/var/www/cowsay-blog/cowposts/
diff --git a/deploy.py b/deploy.py
index 523618bedca86fde33920ca264795b6388710c7f..910dfb7877ecf2f62fdf3205a538db623ab0081e 100644
--- a/deploy.py
+++ b/deploy.py
@@ -2,6 +2,7 @@ # -*- coding: utf-8 -*-
 import jinja2
 import os
 import arrow
+from cowpost import db_connect
 PATH = os.getcwd()
 COWPOSTPATH = PATH + '/cowposts'
 COWDATE_FMT = 'YYYY-MM-DD HH:mm:ss'
@@ -43,16 +44,20 @@                   % cowpost['htmltitle'], 'w') as moo:
             moo.write(cowposttemplate.render(cowpost=cowpost))   
 
 
+def read_from_db():
+    with db_connect() as conn:
+        cur = conn.cursor()
+        cur.execute('''
+            select date
+                 , title || '.html' as htmltitle
+                 , cowtext
+            from cowposts
+            order by id desc''')
+        return cur.fetchall()
+
+
 def cowmain():
-    os.chdir(COWPOSTPATH)
-    cowlinelists = []
-    cowpostfiles = os.listdir(COWPOSTPATH)
-    for cowpostfile in cowpostfiles:
-        with open(cowpostfile, 'r') as moo:
-            cowlinelists.append(moo.readlines())
-    cownamedlines = zip(cowpostfiles, cowlinelists)
-    cowdict = make_cowdict(cownamedlines)
-    cowposts = cowblogsort(cowdict)
+    cowposts = read_from_db()
     write_cowfiles(cowposts)