Created
July 12, 2013 08:23
-
-
Save pomahtuk/5982781 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import re | |
from datetime import * | |
from django.db import connection | |
from django.conf import settings | |
from django.core import serializers | |
import simplejson as json | |
def date_conv(obj): | |
import calendar, datetime | |
if isinstance(obj, datetime.datetime): | |
if obj.utcoffset() is not None: | |
obj = obj - obj.utcoffset() | |
millis = int( | |
calendar.timegm(obj.timetuple()) * 1000 + | |
obj.microsecond / 1000 | |
) | |
return millis | |
def dictfetchall(cursor): | |
"Returns all rows from a cursor as a dict" | |
desc = cursor.description | |
return [ | |
dict(zip([col[0] for col in desc], row)) | |
for row in cursor.fetchall() | |
] | |
def indexisto_agent(request): | |
query = request.GET['query'] | |
code = request.GET['code'] | |
AGENT_SECRET = '10SM23AS45hd78' | |
#AGENT_SECRET = settings.AGENT_SECRET | |
result = [] | |
baseString = query + AGENT_SECRET; | |
if code == hashlib.md5(baseString).hexdigest(): | |
cursor = connection.cursor() | |
cursor.execute(query) | |
#result = cursor.fetchall() | |
result = dictfetchall(cursor) | |
description = cursor.description | |
data = json.dumps(result, default=date_conv) | |
return HttpResponse(data, mimetype='application/json') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
urlpatterns = patterns('', | |
url(r'^agent/', 'agent.indexisto_agent'), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment