Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. def initial_log(self, orders):
  2. with self.conn.cursor() as cur:
  3. row_ids = []
  4. for order in orders:
  5. cur.execute('INSERT INTO orders (order_num, order_amount)
  6. VALUES (%s, %s) RETURNING order_id;',
  7. (order.num, order.amount))
  8. row_id = cur.fetchone()[0]
  9. row_ids.append(row_id)
  10. self.conn.commit()
  11. return row_ids
  12.  
  13. def update_log(self, row_ids, updated_orders):
  14. with self.conn.cursor() as cur:
  15. for row_id, order in zip(row_ids, updated_orders):
  16. status_list = order.messages
  17. encoded_status = encode_status(status_list)
  18. cur.execute('UPDATE orders SET (final_order_amount, order_ack,
  19. order_time, status) =
  20. (%s, %s, current_timestamp, %s) WHERE order_id = %s',
  21. (order.final_amount,
  22. order.ack_num, encoded_status, row_id))
  23. self.conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement