-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.rpy
35 lines (26 loc) · 979 Bytes
/
index.rpy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
from StringIO import StringIO
from twisted.python.filepath import FilePath
from twisted.web.resource import Resource
from cropplan import (
load_crops, load_seeds, create_tasks, schedule_tasks, schedule_ical)
HERE = FilePath(__file__).realpath().parent()
CROP_PLAN = HERE.child('2012 Crop Plan.csv')
CROP_VARIETIES = HERE.child('2012 Crop Plan - Varieties.csv')
class FarmSchedule(Resource):
def render_GET(self, request):
crops = load_crops(CROP_PLAN)
seeds = load_seeds(CROP_VARIETIES, crops)
tasks = create_tasks(crops, seeds)
schedule = schedule_tasks(tasks)
output = StringIO()
stdout = sys.stdout
try:
sys.stdout = output
schedule_ical(schedule)
finally:
sys.stdout = stdout
request.setHeader('content-type', 'text/calendar')
return output.getvalue()
resource = Resource()
resource.putChild("farm-schedule.ics", FarmSchedule())