Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. @app.route('/products',methods = ['POST', 'GET'])
  2. def products():
  3. shopnaam = request.form['shopname']
  4. username = request.form['username']
  5. password = request.form['password']
  6. login = 'https://'+shopnaam+'example.com'
  7. url = 'https://'+shopnaam+'.example.com/admin/products.json'
  8.  
  9. payload = {
  10. 'login[email]': username,
  11. 'login[password]': password
  12. }
  13.  
  14. with requests.Session() as session:
  15. post = session.post(login, data=payload)
  16.  
  17. r = session.get(url)
  18. parsed = json.loads(r.text)
  19.  
  20.  
  21. return render_template('producten.html',parsed = parsed)
  22.  
  23. <button class="collapsible">Bekijk product Informatie</button>
  24. <div class="content">
  25. <table id = "productentabel">
  26. <tr class = "header">
  27. <th>ID</th>
  28. <th>Titel </th>
  29. <th>Prijs Exclusief BTW</th>
  30. <th>Prijs Inclusief BTW</th>
  31. <th>Datum</th>
  32.  
  33. {% for product in parsed['products'] %}
  34. <TR>
  35. <TD width="100px" >{{product['id']}}</TD>
  36. <TD width="300px" >{{product['nl']['title']}}</TD>
  37. <TD width="150px">{{product['price_excl']}}</TD>
  38. <TD width="150px">{{product['price_incl']}}</TD>
  39. <TD width="300px">{{product['created_at']}}</TD>
  40. </TR>
  41. </tr>
  42. {% endfor %}
  43. </table>
  44.  
  45. <input class = "exportknop" value="Exporteer product informatie" type="button" onclick="$('#productentabel').table2CSV({header:['ID','Titel','Prijs Exclusief BTW', 'Prijs Inclusief BTW', 'Datum']})">
  46. </div>
  47.  
  48. products: [
  49. {
  50. article_code: "123",
  51. barcode: "456",
  52. brand_id: 2600822,
  53. created_at: "2018-05-31T15:15:34+02:00",
  54. data01: "",
  55. data02: "",
  56. data03: "",
  57. delivery_date_id: null,
  58. has_custom_fields: false,
  59. has_discounts: false,
  60. has_matrix: false,
  61. hits: 0,
  62. hs_code: null,
  63. id: 72660113,
  64. image_id: null,
  65. is_visible: false,
  66. price_excl: 33.0165,
  67. price_incl: 39.95,
  68. price_old_excl: 0,
  69. price_old_incl: 0,
  70. product_set_id: null,
  71. product_type_id: null,
  72. search_context: "123 456 789",
  73. shop_id: 252449,
  74. sku: "789",
  75. supplier_id: 555236,
  76. updated_at: "2018-05-31T15:15:34+02:00",
  77. variants_count: 1,
  78. visibility: "hidden",
  79. weight: 0,
  80.  
  81. links: {
  82. first: ".json",
  83. last: ".json?page=70",
  84. prev: null,
  85. next: ".json?page=2",
  86. count: 3497,
  87. limit: 50,
  88. pages: 70
  89. }
  90.  
  91. while url:
  92. with requests.Session() as session:
  93. post = session.post(login, data=payload)
  94. r = session.get(url)
  95. parsed = json.loads(r.text)
  96. for product in parsed['products']:
  97. print(product['id'], product['nl']['title'])
  98. url = 'https://example/admin/products' + parsed['links']['next']
  99.  
  100. <script>
  101. var dataSet = []
  102. var wurl = ""
  103.  
  104. tablex = $('#tablex').dataTable( {
  105. select: true,
  106. stateSave: true,
  107. colReorder: true,
  108. deferRender: true,
  109. "oLanguage": {"sSearch": "Filter:"},
  110. columns: [
  111. { title: "Number" },
  112. { title: "Client Name" },
  113. { title: "Opened" },
  114. { title: "Closed" },
  115. { title: "Worked" }
  116. ]
  117. } );
  118.  
  119. function generate() {
  120. $.get(wurl, function( data ) {
  121. dataSet = data;
  122. tablex.fnDestroy();
  123. tablex = $('#tablex').dataTable( {
  124. data: dataSet,
  125. select: true,
  126. stateSave: true,
  127. colReorder: true,
  128. deferRender: true,
  129. "oLanguage": {"sSearch": "Filter:"},
  130. columns: [
  131. { title: "Number" },
  132. { title: "Client Name" },
  133. { title: "Opened"},
  134. { title: "Closed"},
  135. { title: "Worked"}
  136. ],
  137. } );
  138. });
  139. };
  140.  
  141. $(document).ready(function() {
  142. wurl = '/api/getdata';
  143. generate()
  144. } );
  145.  
  146. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement