summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Raggam <raggam-nl@adm.at>2011-05-11 17:21:12 (GMT)
committerJohannes Raggam <raggam-nl@adm.at>2011-05-11 17:21:12 (GMT)
commit8f9b06d150db0fa5648058842004aca9e750f8bc (patch)
tree8fbbcdd18fedf387bc749e07b00a7e995e537398
parenta351418394efd238daf89502fe3e8fd2c8bbe153 (diff)
get and get_current with almost finished functionality
-rw-r--r--nop/views.py28
1 files changed, 21 insertions, 7 deletions
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')