from flask import jsonify
# Begin AJAX requests
@cart.route("/api/total")
def total():
count = 0
if "cart" in session:
cart = session.get("cart")
l = [int(i) for i in redis.hvals(getCartKey(cart))]
count = sum(l)
logger.debug('cart %s : %d', cart, count)
data = calculateItems()
data.pop("products")
return jsonify(dict(count=count, **data))
"""Creates a :class:`~flask.Response` with the JSON representation of
the given arguments with an `application/json` mimetype. The arguments
to this function are the same as to the :class:`dict` constructor.
Example usage::
from flask import jsonify
@app.route('/_get_current_user')
def get_current_user():
return jsonify(username=g.user.username,
email=g.user.email,
id=g.user.id)
This will send a JSON response like this to the browser::
{
"username": "admin",
"email": "admin@localhost",
"id": 42
}
For security reasons only objects are supported toplevel. For more
information about this, have a look at :ref:`json-security`.
This function's response will be pretty printed if it was not requested
with ``X-Requested-With: XMLHttpRequest`` to simplify debugging unless
the ``JSONIFY_PRETTYPRINT_REGULAR`` config parameter is set to false.
.. versionadded:: 0.2
"""
version 5
interface any world
policy DROP
protection strong
server "ssh http https icmp ping" accept
client "icmp dns ping" accept
'''
Created on 3 окт. 2016 г.
@author: leah
'''
from collections import deque
k = 10
mas= [[None]*k for i in range(k)]
point = (0,0)
route = deque([lambda x,y: (x+1,y), lambda x,y: (x,y+1), lambda x,y: (x-1,y), lambda x,y: (x,y-1)])
count = 0
while(True):
x,y = point # current point
if mas[x][y] == None:
mas[x][y] = count
count = count +1
else:
break # done
_x,_y = route[0](*point) # next point
if (_x >= k) or (_y >= k) or (_x < 0) or (_y < 0): # check arrays overflow
route.rotate(-1) #change direction
elif mas[_x][_y] != None:
route.rotate(-1) #change direction
point = route[0](*point)
for i in mas:
print(" ".join(str(i)))
[ 0 , 3 5 , 3 4 , 3 3 , 3 2 , 3 1 , 3 0 , 2 9 , 2 8 , 2 7 ]
[ 1 , 3 6 , 6 3 , 6 2 , 6 1 , 6 0 , 5 9 , 5 8 , 5 7 , 2 6 ]
[ 2 , 3 7 , 6 4 , 8 3 , 8 2 , 8 1 , 8 0 , 7 9 , 5 6 , 2 5 ]
[ 3 , 3 8 , 6 5 , 8 4 , 9 5 , 9 4 , 9 3 , 7 8 , 5 5 , 2 4 ]
[ 4 , 3 9 , 6 6 , 8 5 , 9 6 , 9 9 , 9 2 , 7 7 , 5 4 , 2 3 ]
[ 5 , 4 0 , 6 7 , 8 6 , 9 7 , 9 8 , 9 1 , 7 6 , 5 3 , 2 2 ]
[ 6 , 4 1 , 6 8 , 8 7 , 8 8 , 8 9 , 9 0 , 7 5 , 5 2 , 2 1 ]
[ 7 , 4 2 , 6 9 , 7 0 , 7 1 , 7 2 , 7 3 , 7 4 , 5 1 , 2 0 ]
[ 8 , 4 3 , 4 4 , 4 5 , 4 6 , 4 7 , 4 8 , 4 9 , 5 0 , 1 9 ]
[ 9 , 1 0 , 1 1 , 1 2 , 1 3 , 1 4 , 1 5 , 1 6 , 1 7 , 1 8 ]