Commits

Anonymous committed 9c7808f

first commit

Comments (0)

Files changed (5)

application_werk.py

+#-*-coding:utf-8 -*-
+
+import os
+import codecs
+from werkzeug.wrappers import BaseRequest, BaseResponse, Response
+from werkzeug.formparser import parse_form_data
+from werkzeug.utils import redirect
+from werkzeug.wsgi import wrap_file
+from jinja2 import Template
+import csv
+from datetime import datetime,date
+import templates
+
+
+##UTILS##
+
+def get_data(mode="a",file="week.csv"):
+    """ process an org-agenda to get the data into a csv file """
+    
+    os.system("""
+emacs -batch -l dummy_org_conf -eval '(org-batch-agenda-csv "%s" org-agenda-include-diary t org-agenda-files (quote ("~/upload/")))' > %s"""% (mode,file)
+)
+
+def read_data(file):
+    """ read data from a csv file return a well list of well formated entry"""
+    reader = csv.reader(open(file))
+    agenda_list = []
+    for elem in reader:
+        agenda_list.append(format_dict(elem))
+    temp_dates = [elem['date'] for elem in agenda_list]
+    dates = []
+    for elem in temp_dates:
+        if elem not in dates:
+            dates.append(elem)
+    
+    return {'agenda':agenda_list,'dates':dates}
+                        
+
+def format_dict(line):
+    """ get a line of csv file and process data into a clean dictionary """
+    elem_dict = {
+        'category':codecs.utf_8_decode(line[0])[0],
+        'head':codecs.utf_8_decode(line[1])[0],
+        'type':codecs.utf_8_decode(line[2])[0],
+        'todo':codecs.utf_8_decode(line[3])[0],
+        'tag':codecs.utf_8_decode(line[4])[0].split(':'),
+        'date':datetime.strptime(codecs.utf_8_decode(line[5])[0],'%Y-%m-%d'),
+        'time':codecs.utf_8_decode(line[6])[0],
+        'extra':codecs.utf_8_decode(line[7])[0],
+        'priority1':codecs.utf_8_decode(line[8])[0],
+        'priorityn':codecs.utf_8_decode(line[9])[0]
+        }
+    print elem_dict
+    return elem_dict
+
+##VIEWS
+
+def display_week(request):
+    try :
+        agenda=read_data("week.csv")
+    except:
+        return  redirect('/upload/')
+    template = Template("%s %s" %(templates.header,templates.agenda))
+    return BaseResponse(template.render(
+            today = date.today(),
+            agenda = agenda,
+            ,
+            name="Weekly"
+            ),
+                        mimetype='text/html'
+                        )
+
+def generate_data(request,mode):
+    get_data(mode)
+    return  redirect('/')
+
+
+
+def display_upload(request):
+    template = Template("%s %s"%(templates.header,templates.upload_form))
+    return BaseResponse(template.render(),mimetype='text/html')
+
+def save_data(request):
+    f = request.files.get('org')
+    f.save('upload/%s'%f.filename)
+    template = Template("%s %s"%(templates.header,templates.sucess))
+    return BaseResponse(template.render(),mimetype='text/html')
+
+def application(environ, start_response):
+    request = BaseRequest(environ)
+    if request.path == '/':
+        response = display_week(request)
+
+    elif request.path == '/generate/week/':
+        response = generate_data(request,"a")
+
+    elif request.path == '/upload/':
+        if request.method == 'GET':
+            response = display_upload(request)
+
+        if request.method == 'POST':
+            response = save_data(request)
+            
+    else:
+        response = Response('Go to hell',status=404)
+        
+    return response(environ, start_response)
+
+if __name__ == '__main__':
+    from werkzeug.serving import run_simple
+    run_simple('localhost', 8000, application,use_debugger=True, use_reloader=True,static_files={"/jquery.js":"jquery.js"})
+header = """
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+lang="en" xml:lang="en">
+<head>
+<title>{{name}} Agenda</title>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+<meta name="description" content=""/>
+<meta name="keywords" content=""/>
+<script src="/jquery.js"></script>
+
+<script>
+  $(document).ready(function(){
+   $('span').click(function(){
+    value = "."+$(this).attr('class');
+    $('span').parent().parent().hide()
+    $(value).parent().parent().show()
+    if($('#reset').length == 0){
+        $('body').append("<div id='reset'>Reset</div>'");
+        $('#reset').click(function(){$('span').parent().parent().show()})
+        }
+    });
+    
+ });
+
+</script>
+
+<style type="text/css">
+<!--/*--><![CDATA[/*><!--*/
+body{
+{% if agenda %}  width: {{agenda.dates|length*410}}  px; {% endif %}
+  overflow: auto;
+}
+.day{
+  float:left;
+  padding:10px;
+  border-left:1px solid grey;
+  width: 400px;
+}
+h1{
+  border-bottom : 1px solid grey;
+}
+h2{
+
+  display: inline;
+}
+h3{
+  text-align: center;
+  text-decoration: underline
+}
+.header{
+  border: solid 1px grey;
+  background: black;
+  color: #dedede;
+  text-align: center;
+}
+p{
+  font-size:20px;
+  color: grey;
+}
+p span{
+background : #000000
+}
+.task{
+float:left;
+width:180px;
+border:solid 1px grey;
+padding:3px;
+}
+
+.deadline{
+  font-size:16px;
+  font-weight:bold;
+  color:red;
+}
+
+.overdue{
+  background:;
+}
+.cool{
+color:grey!important;
+background:grey!important;
+}
+
+.today{
+  background: yellow;
+}
+#menu ul{
+  list-style-type: none;
+  background: black;
+  }
+#menu li{
+  display:inline;
+  background: grey;
+  margin: 5px;
+  padding: 5px;
+  border: solid black 1px;
+
+}
+/*]]>*/-->
+</style>
+"""
+
+agenda = """
+<h1>Agenda View</h1>
+<div id="menu">
+<ul>
+  <li>
+    <a href='/upload/'>Upload another org file</a>
+  </li>
+  <li>
+    <a href="/generate/week/">regenerate week</a>
+  </li>
+</ul>
+</div>
+<h1>{{name}} Agenda from:</h1>
+<h2> {{agenda.dates[0].strftime('%a %d %h %Y') }} to {{agenda.dates[-1].strftime('%a %d %h %Y')}}</h2>
+
+{% for elem in agenda.dates %}
+  <div class="day 
+     {%if elem.strftime('%a %d %h %Y') == today.strftime('%a %d %h
+     %Y') %}
+       today
+     {%endif%}">
+    <h1>{{elem.strftime('%a %d %h %Y')}}</h1>
+    {%for task in agenda.agenda %}
+        {%if task.date == elem  %}
+         <div class="task {% if task.priorityn|int > 1000 %} 
+               overdue {%endif%}
+               {%if task.todo == "DONE" %}cool {%endif%}
+         ">
+            <div class="header {{task.type}}">
+              <h2>{{task.head}} ({{task.category}})</h2>
+              <p>  
+                    {{task.todo}} {%if task.priorityn|int < 1000 %}{{task.extra}} {%endif%}
+              </p>
+                   
+            </div>
+            <p> </p>
+            <h3>tags</h3>
+<p>
+ {%for tag in task.tag %} <span class="{{tag}}">{{tag}}</span> {%endfor%}
+</p>
+         </div>
+        {% endif %}
+    {%endfor%}
+  </div>
+{%endfor%}
+"""
+
+upload_form = """
+<h1>Gimme your org file motherfucker</h1>
+<form method="post" action="" enctype="multipart/form-data">
+  <input type="file" name="org" />
+  <input type='submit' value='take it or leave it' />
+</form>
+"""
+
+sucess="""
+<h1>Hey well done, you're not as badass as you seem !</h1>
+<form action="/generate/week/" method="GET">
+<input type="submit" value="Gimme my agenda bastard!">
+</form> 
+"""

Binary file added.

Empty file added.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.