from flask import Blueprint, render_template from config import orders from tools import crud blue = Blueprint('orders', __name__, url_prefix='/orders') crud(blue, orders) @blue.route('/', methods=['GET', 'POST']) def order_now(): return 'yusof', 200
from how.instance import how from bson import ObjectId from tools.media import insert_img from how.articlate import articlate, parse, _aline import json from datetime import datetime import random blue = Blueprint('how', __name__, template_folder='templates', url_prefix='/hows') crud(blue, hows, template='how/index', load=lambda x: (x, { 'no_secondary': True }), skeleton=how) @blue.route('/<_id>/<level_1>/<level_2>/media/+', methods=['POST']) def add_image(_id, level_1, level_2): (l1, l2) = (int(level_1) - 1, int(level_2) - 1) article = hows.find_one({'_id': ObjectId(_id)}) level_1 = article['level_1'][l1] level_2 = level_1['level_2'][l2] raw_img = request.files['image'] o = ObjectId() o = insert_img(raw_img.read(), o, sizes=()) level_2['i'] = str(o[0])
from flask import Blueprint, request, jsonify from config import categories from tools import crud, request_attributes from pymongo import DESCENDING blue = Blueprint('categories', __name__, url_prefix='/tags') """ ancestors: [ { title: _id: } ] """ crud(blue, categories, skeleton={ 'title': '', 'ancestors': [], }) @blue.route('/sug/') def suggest_categories(query, size): query = query if query else request_attributes(request, query=str)['query'] size = size if size else request_attributes(request, size=int)['size'] __categories = categories.find( { '$or': [ { '$text': { '$search': query } },
crud( blue, hybrids, template='hybrid/index', getter=False, load=lambda x: (x, { 'dictionary': [ 'چای سبز', 'آبتره', 'آبقاشقی', 'آجیل شمع', 'آرد ثعلب', 'آروم', 'آریستلچیا کنترتا', 'آساروم', 'آسرولا', 'آسیمینا', 'آفتابگردان', 'آقطی', 'آقطی سیاه', 'ازگیل ژاپنی', 'اسپند', 'اسطوخودوس تیری' ], 'tags': [['شامپو', 8, 9, 10], ['ادویه', 1, 2], ['لاغری', 0, 1, 6]] }), skeleton={ 'title': 'new Hybrid :0', # 'cure': '', # is remedy # 'info': '', # [ans] is specifications.0.p 'nature': -1, 'table': [], 'remedy': '', 'countable': False, 'sub': [], 'qnt': '60 Veggie Caps', 'combo': { 'title': 'lorem ipsum dollor hapa lut', 'value': { 'our': 300, }, # ractive converts to price 'reviews': { 'score': { 'value': 4.5, 'population': 833, } }, 'img': ['https://www.images-iherb.com/m/MLI-00952-15.jpg'], 'save': 2, }, 'dimensions': { 'weight': { 'shipping': .18, 'pure': .15, }, 'x': 2, 'y': 2.5, 'z': 3.5, }, 'code': { 'pr': 'THR-00287', 'upc': '693749002871', }, 'value': { 'our': 300, 'msrp': 302 }, # ractive converts to price 'brand': { 'title': 'lotus', 'link': 'http://lotus.com', }, 'summary': { 'Expiration Date': 'Feb 2019', 'Shipping Weight': 12, 'Product Code': 'THR-80303', 'UPC Code': '693749803034', 'Package Quantity': '60 Veggie Caps', 'Dimensions': [3.4, 1.9, 1.9], }, 'specifications': [ { 'title': 'Description', 'ul': [ 'Dietary Supplement', 'NSF - Certified by Sport', ], 'p': [ '''The keystone of every nutritional product line is a multi-vitamin/mineral supplement. A multi-vitamin/mineral product is the starting point for every individual's supplementation needs and therefore it should contain all of the essential nutrients.''', '''Because of the state of the current food supply and because very few individuals eat the recommended five daily servings of fruits and vegetables, nutrition experts agree that a multi-vitamin/mineral supplement should be taken daily. Even the Journal of the American Medical Association – not usually known as a supporter of nutritional supplements – suggests that everyone should take a multi-vitamin/mineral supplement (JAMA 2002;287:3127-3129). A good multi-vitamin/mineral nutritional supplement could be considered "dietary insurance" to be certain all of the essential nutrients are being consumed on a daily basis. Even greater health benefits can be realized when a healthy diet is being eaten in addition to taking a multi-vitamin/mineral supplement.''', '''A joint statement issued by the American College of Sports Medicine, the Academy of Nutrition and Dietetics, and the Dietitians of Canada is particularly noteworthy for individuals involved in athletic activities: “Supplements may be required by athletes who restrict energy intakes, use severe weight loss practices, eliminate one or more food groups from their diet, or consume high-carbohydrate diets with low micronutrient density.”''', '''Basic Nutrients 2/Day provides a comprehensive multi-vitamin/mineral complex. Its key nutritional features include 2,000 IU of vitamin D3 and 400 mcg of vitamin K (in K1 and K2 forms) per serving, in addition to having mixed tocopherols, bioactive B-vitamins, and amino acid-chelated minerals, including calcium and magnesium – all in a two-capsule-per-day delivery system. Basic Nutrients 2/Day makes it easy for individuals to obtain foundational nutritional support.''', '''Basic Nutrients 2/Day is NSF Certified for Sport.''', ] }, { 'title': 'Suggested Use', 'p': [ '''Take 2 capsules daily or as recommended by your-health-care practitioner.''', ], }, { 'title': 'Other Ingredients', 'p': [ '''Hypromellose (derived from cellulose) capsule, microcrystalline cellulose, calcium laurate, silicon dioxide.''', '''Gamma tocopherol does not have a recognized IU equivalent.''', ], }, { 'title': 'Warnings', 'p': [ '''Tamper Evident: Use only if bottle is sealed. Store tightly sealed in a cool, dry place.''', '''If pregnant, consult your health-care practitioner before using this product.''', ], }, ], 'supplement_facts': { 'title': 'Supplement Facts', 'serving': [[ 'Serving Size', 'Two Capsules', ], [ 'Serving Per Container', '30', ]], 'supplements': [ { 'element': 'Vitamin A (3,000 IU from Beta Carotenes and 2,000 IU as Palmitate)', 'amo': '5,000 IU', 'dv': '100%', }, { 'element': 'Vitamin C (as Ascorbic Acid)', 'amo': '250 mg', 'dv': '417%', }, { 'element': 'Vitamin D (as Vitamin D3)', 'amo': '2,000 IU', 'dv': '500%', }, { 'element': 'Vitamin E (as d-Alpha Tocopheryl Acid Succinate)', 'amo': '20 IU', 'dv': '67%', }, { 'element': 'Vitamin K (200 mcg as Vitamin K1 and 200 mcg as Vitamin K2)', 'amo': '400 mcg', 'dv': '500%', }, { 'element': 'Thiamin (as Thiamin HCI)', 'amo': '50 mg', 'dv': '3,333%', }, ] }, 'reviews': init_structure(), 'img': [ 'https://www.images-iherb.com/y/THR-00287-6.jpg', 'https://www.images-iherb.com/y/THR-00287-5.jpg', ], 'categories': [], })
from config import fs, faces from PIL import Image import numpy as np from threading import Thread from face.core import analyse from bson import ObjectId # from face.age_gender import FaceCV import cv2 from tools.media import insert_img from datetime import datetime from tools import crud from random import randint import traceback blue = Blueprint('face', __name__, url_prefix='/face') crud(blue, faces, getter=False) # model = FaceCV(depth=16, width=8) banners = [{ 'img': '/static/img/face_banner/0.jpg', 'position': -110 }, { 'img': '/static/img/face_banner/1.jpg', 'position': -15 }, { 'img': '/static/img/face_banner/2.jpg', 'position': -105 }, { 'img': '/static/img/face_banner/3.jpg', 'position': -85 }, { 'img': '/static/img/face_banner/4.jpg',
def crud(): blue = Blueprint('analytics', __name__, template_folder='templates') from tools import crud crud(blue, analytics) jump_back = 5 - 1 @blue.route('/live/', methods=['GET', 'POST']) @blue.route('/live/<int:limit>', methods=['GET', 'POST']) @blue.route('/live/<int:limit>/<int:skip>', methods=['GET', 'POST']) def live(limit=5, skip=None): if not skip: skip = analytics.count() - jump_back documents = analytics.find( {'order': { "$gte": skip, "$lt": skip + limit }}) documents = [obj2str(document) for document in documents] _documents = {} for document in documents: if document['collection'] not in _documents: _documents[document['collection']] = [] _documents[document['collection']].append( ObjectId(document['document'])) for _collection, _ids in _documents.items(): from importlib import import_module mod = import_module('config') collection = getattr(mod, _collection) list_of_documents = collection.find({'_id': {"$in": _ids}}) doc_dict = {} for d in list_of_documents: doc_dict[d['_id']] = d _documents[_collection] = [ doc_dict[d] for d in _documents[_collection] ] _list = [] for collection_name, collection_set in _documents.items(): _list.extend(collection_set) _list = { 'list': [obj2str(d) for d in _list], 'analytic_order': skip + limit } return jsonify(_list) trending = {} @blue.route('/trending/*') def clear_trending(): trending.clear() return "['success', 200]", 200 @blue.route('/trending/<_id>+') def insert_trending(_id): trending[_id] = True return "['success', 200]", 200 @blue.route('/trending/-') def get_trending(): return jsonify(show_trending()) @blue.route('/--/<collection>/<_id>/') @login_required def fake(collection, _id): # check for user privileges _analyze(collection, _id, 'paid') return json.dumps({ 'success': True, 'message': 'you faked purchasing' }), 200, { 'ContentType': 'application/json' } return blue
def on_update_redundancy(_review): collection = _review['coolie']['type'] collection = globals()[collection] document = _review['coolie']['_id'] document = collection.find_one({'_id': document}) document['reviews'] = update_structure(document['reviews']) collection.save(document) crud(blue, topics, skeleton=review, template='review', redundancies={ 'update': on_update_redundancy, 'insert': on_insert_redundancy, 'delete': on_delete_redundancy }) def bring_reviews(document, limit=5, skip=0): _reviews = document['reviews']['reviews'] _reviews = _reviews[skip:skip + limit] _top_review = document['reviews']['top_review'] document['reviews']['reviews'] = topics.find({'_id': {'$in': _reviews}}) document['reviews']['top_review'] = topics.find_one({'_id': _top_review}) return document
from flask import Blueprint, request, jsonify, render_template from config import pages from tools import crud skeleton = { 'name': "", 'html': '', } blue = Blueprint('page', __name__, template_folder='templates', url_prefix='/pages') crud(blue, pages, template='page/index', skeleton=skeleton) @blue.route('/the/<name>') def symlink_get(name): page = pages.find_one({'name': name}) return render_template('page/index.html', **page)
'dv': '3,333%', }, ] }, 'reviews': init_structure(), 'img': [ 'https://www.images-iherb.com/y/THR-00287-6.jpg', 'https://www.images-iherb.com/y/THR-00287-5.jpg', ], 'categories': [], } blue = Blueprint('pr', __name__, url_prefix='/pr') crud( blue, products, template='product/index', load=lambda x: ({'pr': bring_reviews(x, 5)}, ctx), skeleton=pr, projection=combo ) @blue.route('/<_id>/@reviews/+', methods=['GET', 'POST']) def insert_review(_id): if not current_user.is_authenticated: abort(401) _id = ObjectId(_id) author_id = current_user._id author_name = current_user.first_name or current_user.last_name or current_user.username author_img = current_user.img if hasattr(current_user, 'img') else '/static/semantic/examples/assets/images/avatar/{}.jpg'.format(random.choice(['nan', 'tom'])) _json = request_attributes(request, type=int, value=int) if 'text' in request.values: _json['text'] = request.values['text']