From 8f9b06d150db0fa5648058842004aca9e750f8bc Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Wed, 11 May 2011 19:21:12 +0200 Subject: get and get_current with almost finished functionality diff --git a/nop/views.py b/nop/views.py index 6fec3a3..c485beb 100644 --- a/nop/views.py +++ b/nop/views.py @@ -1,8 +1,7 @@ from django.http import HttpResponse from models import Master import json -#import time -#from datetime import date, datetime, time, timedelta +import time def get_current(request): @@ -18,9 +17,24 @@ def get_current(request): return HttpResponse(response, mimetype='text/plain') def get(request, year=None, month=None, day=None, hour=None, minute=None): - #if year is None and month is None and day is None: - # today = datetime.combine(date.today(), time(6, 0)) - #else: - # today = datetime.strptime('%s__%s__%s__06__00' % (year, month, day), '%Y__%m__%d__%H__%M') - return None + try: + # tm_year,tm_mon,tm_mday,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst + ts = int(time.mktime(( + int(year), + int(month), + int(day), + int(hour), + int(minute),0,0,0,-1))) * 1000000 + + result = Master.objects.using('nop').filter(timestamp__lt=ts)[:5] + response = json.dumps( + [{'artist': item.artist, 'title': item.title, 'album': item.album, + 'datetime': time.strftime('%Y-%m-%d %H:%M', + time.localtime(item.timestamp//1000000)), + 'showtitle': item.showtitle} for item in result]) + except: # all errors + response = '' + + #return HttpResponse(response, mimetype='application/json') + return HttpResponse(response, mimetype='text/plain') -- cgit v0.10.2