#!/usr/bin/python3
# -*- coding: utf-8 -*-

from flask import Flask, render_template, url_for, request, jsonify
from ..db import database as _db
from . import houses

''' show the information of specific house'''
no_found = jsonify("House not found")

# 接受信息: house_id:房屋的id

@houses.route('/house_infopage/')
def house_infopage():
    return render_template('templates/house_info.html')


@houses.route('/house_info/<int:house_id>')
def house_info(house_id):
    db = _db.getdb()
    cur = db.cursor()
    info = cur.execute("SELECT * FROM houses WHERE id = ?", (house_id,)).fetchall()
    if info == []:
        return no_found
    else:
        info = info[0]  # tuple -> list
    cur.close()
    return jsonify({
        'address': info[1],
        'title': info[2],
        'description': info[3],
        'master': info[4],
        'rank': info[5],
        'pictures': info[6],
        'value': info[8]})
