From a351418394efd238daf89502fe3e8fd2c8bbe153 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Tue, 10 May 2011 17:50:39 +0200 Subject: add nop initial app diff --git a/nop/__init__.py b/nop/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nop/models.py b/nop/models.py new file mode 100644 index 0000000..8bb87af --- /dev/null +++ b/nop/models.py @@ -0,0 +1,36 @@ +from django.db import models + +class Master(models.Model): + timestamp = models.BigIntegerField(primary_key=True) + cart = models.IntegerField() + len = models.IntegerField(null=True, blank=True) + showtitle = models.CharField(max_length=765, blank=True) + title = models.CharField(max_length=765, blank=True) + artist = models.CharField(max_length=765, blank=True) + album = models.CharField(max_length=765, blank=True) + ismusic = models.IntegerField(null=True, blank=True) + class Meta: + db_table = u'master' + ordering = ['-timestamp'] + + +class Standby(models.Model): + timestamp = models.BigIntegerField(primary_key=True) + cart = models.IntegerField() + len = models.IntegerField(null=True, blank=True) + showtitle = models.CharField(max_length=765, blank=True) + title = models.CharField(max_length=765, blank=True) + artist = models.CharField(max_length=765, blank=True) + album = models.CharField(max_length=765, blank=True) + ismusic = models.IntegerField(null=True, blank=True) + class Meta: + db_table = u'standby' + ordering = ['-timestamp'] + +class State(models.Model): + timestamp = models.BigIntegerField(primary_key=True) + state = models.CharField(max_length=96, blank=True) + class Meta: + db_table = u'state' + ordering = ['-timestamp'] + diff --git a/nop/urls.py b/nop/urls.py new file mode 100644 index 0000000..a4700cf --- /dev/null +++ b/nop/urls.py @@ -0,0 +1,7 @@ +from django.conf.urls.defaults import patterns, url +from views import get, get_current + +urlpatterns = patterns('', + url(r'^$', get_current), + url(r'^(?P\d{4})/(?P\d{1,2})/(?P\d{1,2})/(?P\d{1,2})/(?P\d{1,2})/?$', get), +) diff --git a/nop/views.py b/nop/views.py new file mode 100644 index 0000000..6fec3a3 --- /dev/null +++ b/nop/views.py @@ -0,0 +1,26 @@ +from django.http import HttpResponse +from models import Master +import json +#import time +#from datetime import date, datetime, time, timedelta + +def get_current(request): + + #current = int(time.time())*1000000 + #time.gmtime(Master.objects.using('nop').all()[6000].timestamp//1000000) + # select all where timestamp < givenTS, get most recent one -> order DESC + + # reverse sorted. get the first object = last played + result = Master.objects.using('nop').all()[0] + response = json.dumps({'artist': result.artist, 'title': result.title}) + + #return HttpResponse(response, mimetype='application/json') + 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 + -- cgit v0.10.2