Example #1
0
def from_xml_to_order(root):
    order = {
        'order_name': root.attrib['order_name'],
        'order_price': root.attrib['order_price'],
        'order_country': root.attrib['order_country'],
        'delivery_time': root.attrib['delivery_time'],
        'goods': [{
                      'good_country': el.attrib['good_country'],
                      'good_name': el.attrib['good_name'],
                      'good_price': el.attrib['good_price'],
                      'good_production_date': el.attrib['good_production_date']
                  } for el in root.find('goods').iter('good')]
    }
    new_order = Order(order['order_name'], order['order_country'], datetime.strptime(order['delivery_time'],
                                                                                     '%Y-%m-%dT%H:%M:%S'))
    new_order.price_of_order = order['order_price']
    new_order.goods = order['goods']
    return new_order
def add_g_to_o(params):
    print "adding"
    g_path = STORAGE_ROOT+'/good-'+params['name']+'_'+params['country']+'_'+params['g_id']+'.json'
    t_good = json.load(open(g_path, 'r'))
    t_good = dict_to_good(t_good)
    print t_good

    o_path = STORAGE_ROOT+'/order-'+params['to']+'_'+params['ord_c']+'_'+params['o_id']+'.json'
    t_order = json.load(open(o_path, 'r'))
    #print t_good, t_order
    new_order = Order(t_order['name'], t_order['country'], datetime.strptime(t_order['delivery_time'], '%d.%m.%Y').strftime('%d.%m.%Y'))
    new_order.goods = dict_to_goods(t_order['goods'])
    new_order.price_of_order = int(t_order['price']) + int(t_good.good_price)
    new_order.goods.append(t_good)
    obj = new_order.to_dict()
    full_path = "%s\%s-%s_%s_%s.json" % (STORAGE_ROOT, 'order', new_order.order_name, new_order.delivery_country,
                                         params['o_id'])
    wfile = open(full_path, 'w')
    json.dump(obj, wfile)
    wfile.close()
Example #3
0
from datetime import datetime

good_1 = Good('shovel', 'Germany', 50000, datetime(2013, 12, 11))
good_2 = Good('steel', 'Italy', 25000, datetime(2013, 8, 4))
good_3 = Good('snow', 'Russia', 5000, datetime(2012, 10, 12))
good_4 = Good('kola', 'Nigeria', 9000, datetime(2012, 12, 14))
good_5 = Good('ananases', "USA", 80000, datetime(2012, 11, 15))
good_6 = Good('coffee', "Africa", 75600, datetime(2011, 10, 24))
good_7 = Good('meat', "Mexico", 35200, datetime(2013, 9, 8))
good_8 = Good('bread', "Japan", 3200, datetime(2013, 10, 6))
good_9 = Good('bad', "UK", 76580, datetime(2013, 11, 10))
all_goods = [good_1, good_2, good_3, good_4, good_5, good_6, good_7, good_8, good_9]

order_1 = Order("'Avangard'", 'USA', datetime(2013, 10, 24))
order_1.goods = [good_1, good_2, good_3]
order_1.price_of_order = Order.total_price(order_1)

order_2 = Order("'Azazaza'", 'RUS', datetime(2013, 11, 14))
order_2.goods = [good_4, good_5, good_6]
order_2.price_of_order = Order.total_price(order_2)

order_3 = Order("'Trust'", 'UK', datetime(2014, 2, 8))
order_3.goods = [good_7, good_8, good_9]
order_3.price_of_order = Order.total_price(order_3)
all_orders = [order_1, order_2, order_3]


new_dict = {'orders': []}
new_dict['orders'].append(Order.to_dict(order_1))
new_dict['orders'].append(Order.to_dict(order_2))
new_dict['orders'].append(Order.to_dict(order_3))
Example #4
0
def dict_to_order(order):
    new_order = Order(order['name'], order['country'], order['delivery_time'])
    new_order.price_of_order = order['price']
    new_order.goods = dict_to_good(order['goods'])
    return new_order