Esempio n. 1
0
def get_item(id):
    conn = sqlite3.connect(filename)
    c = conn.cursor()
    response = provider_02_pb2.Response()
    for i in c.execute("SELECT * FROM items WHERE uuid = ?", (id, )):
        response.item.id = id
        response.item.price = i[1]
        response.item.name = i[2]
        response.item.description = i[3]
        for category in c.execute("SELECT * FROM category WHERE id = ?",
                                  (response.item.id, )):
            response.item.category.append((category[1]))
        for photo in c.execute("SELECT * FROM photos WHERE id = ?",
                               (response.item.id, )):
            response.item.photos.append(photo[1])
        for material in c.execute("SELECT * FROM materials WHERE id = ?",
                                  (response.item.id, )):
            response.item.material = material[1]
        for sex in c.execute("SELECT * FROM sex WHERE id = ?",
                             (response.item.id, )):
            response.item.sex.append(sex[1])
    conn.close()
    if response.item.id == "":
        abort(404)
    return bi.hexlify(response.SerializeToString())
Esempio n. 2
0
 def convert_item(self, response):
     data = provider_02_pb2.Response()
     data.ParseFromString(bi.unhexlify(response.content))
     if data.HasField('error'):
         return {
             'error': {
                 'message': str(data.error.code),
                 'provider': self.provider
             }
         }
     converted = {}
     converted['item'] = {}
     converted['item']['provider'] = self.provider
     converted['item']['id'] = data.item.id
     converted['item']['description'] = data.item.description
     converted['item']['price'] = data.item.price
     converted['item']['name'] = data.item.name
     converted['item']['sex'] = []
     converted['item']['category'] = []
     for sex in data.item.sex:
         converted['item']['sex'].append(sex)
     for category in data.item.category:
         converted['item']['category'].append(category)
     #TODO: kolor
     converted['item']['provider_specific'] = {}
     converted['item']['provider_specific']['photos'] = []
     for photo in data.item.photos:
         converted['item']['provider_specific']['photos'].append(photo)
     converted['item']['provider_specific']['material'] = data.item.material
     return converted
Esempio n. 3
0
def price_more(amount):
    conn = sqlite3.connect(filename)
    c = conn.cursor()
    response = provider_02_pb2.Response()
    for item in c.execute("SELECT * FROM items WHERE price >= ?", (amount, )):
        new = response.items.id.append(item[0])
    conn.close()
    if len(response.items.id) == 0:
        abort(404)
    return bi.hexlify(response.SerializeToString())
Esempio n. 4
0
def get_sex(id):
    conn = sqlite3.connect(filename)
    c = conn.cursor()
    response = provider_02_pb2.Response()
    for item in c.execute("SELECT  * FROM sex WHERE sex = ?", (id, )):
        new = response.items.id.append(item[0])
    conn.close()
    if len(response.items.id) == 0:
        abort(404)
    return bi.hexlify(response.SerializeToString())
Esempio n. 5
0
 def convert_items(self, response):
     data = provider_02_pb2.Response()
     data.ParseFromString(bi.unhexlify(response.content))
     if data.HasField('error'):
         return {
             'error': {
                 'message': str(data.error.code),
                 'provider': self.provider
             }
         }
     converted = {}
     converted['items'] = []
     for item in data.items.id:
         converted['items'].append({'provider': self.provider, 'id': item})
     return converted
Esempio n. 6
0
def not_found(error):
    response = provider_02_pb2.Response()
    response.error.message = "Not found"
    response.error.code = 404
    return make_response(bi.hexlify(response.SerializeToString()), 404)