def photos(): k = Kensing() if not request.json: # We could default to a GET here new_photo = [] index = 0 all_photos = [] for photo in k.get_all_photos(): for value in photo: if index == 1: new_photo.append(repr(str(value))) else: new_photo.append(value) index = index + 1 all_photos.append(new_photo) return jsonify({'photos': all_photos}), 200 elif not 'photo_data' in request.json: #This is where we posted json but we aren't sending any data abort(400) else: #POST photo_data = request.json['photo_data'] photo_date = request.json['photo_date'] rating = 0 if 'rating' in request.json: rating = request.json['rating'] album = request.json['album_name'] if k.insert_new_photo(photo_data, photo_date, rating, album): return 201 else: abort(400)
#!flask/bin/python from Kensing import Kensing import time import cStringIO import sqlite3 k = Kensing() picture = open('/Users/jonathanlong/Desktop/IMG_8788.JPG', 'rb') picture_data = picture.read() current_time = time.strftime("%d/%m/%Y-%H:%M:%S") # k.insert_new_album("Yosemite") # print k.album_id_for_name('Yos') picture_buffer = sqlite3.Binary(picture_data) # print picture_buffer.__hash__() # k.rate_photo(picture_buffer, 5) k.insert_new_photo(picture_buffer, current_time) # k.add_photo_data_to_album(picture_buffer, 'Zion') # k.add_photo_data_to_album(picture_buffer, 'Disney') # k.add_photo_data_to_album(picture_buffer, 'Yosemite') # k.insert_new_photo(buffer(picture_data), current_time, "Yosemite") # k.insert_new_photo(buffer(picture_data), current_time, "Yosemite") zion_album = k.get_all_photos() new_photo = [] index = 0 for photo in zion_album: for value in photo: if index == 1: print "HERE" new_photo.append(repr(str(value)))
#!flask/bin/python from Kensing import Kensing import urllib, cStringIO, sqlite3 import json k = Kensing() thefile = open('/Users/jonathan_long/Desktop/image.png', 'rb').read() # print thefile # print k.photos_for_album("test") k.insert_photo(thefile, "png") k.insert_album("test") photos = k.column_names(k.PHOTOS_TABLE) print json.dumps({"photos":photos})