products.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:server-application 作者: foodshipper 项目源码 文件源码
def get(ean):
        with db:
            with db.cursor() as cursor:
                cursor.execute("SELECT name, type FROM products"
                               " WHERE ean=%s", (ean,))
                product = cursor.fetchone()
                if product is not None:
                    return {
                        "ean": ean,
                        "name": product[0],
                        "type": product[1]
                    }
                else:
                    result = request_product(ean)
                    if result is not None:
                        Product.add_product(result['ean'], result['name'], result['type'])
                        return result

                    abort(404, message="Product with EAN {} does not exist.".format(ean))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号