Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @app.route('/products',methods = ['POST', 'GET'])
- def products():
- shopnaam = request.form['shopname']
- username = request.form['username']
- password = request.form['password']
- login = 'https://'+shopnaam+'example.com'
- url = 'https://'+shopnaam+'.example.com/admin/products.json'
- payload = {
- 'login[email]': username,
- 'login[password]': password
- }
- with requests.Session() as session:
- post = session.post(login, data=payload)
- r = session.get(url)
- parsed = json.loads(r.text)
- return render_template('producten.html',parsed = parsed)
- <button class="collapsible">Bekijk product Informatie</button>
- <div class="content">
- <table id = "productentabel">
- <tr class = "header">
- <th>ID</th>
- <th>Titel </th>
- <th>Prijs Exclusief BTW</th>
- <th>Prijs Inclusief BTW</th>
- <th>Datum</th>
- {% for product in parsed['products'] %}
- <TR>
- <TD width="100px" >{{product['id']}}</TD>
- <TD width="300px" >{{product['nl']['title']}}</TD>
- <TD width="150px">{{product['price_excl']}}</TD>
- <TD width="150px">{{product['price_incl']}}</TD>
- <TD width="300px">{{product['created_at']}}</TD>
- </TR>
- </tr>
- {% endfor %}
- </table>
- <input class = "exportknop" value="Exporteer product informatie" type="button" onclick="$('#productentabel').table2CSV({header:['ID','Titel','Prijs Exclusief BTW', 'Prijs Inclusief BTW', 'Datum']})">
- </div>
- products: [
- {
- article_code: "123",
- barcode: "456",
- brand_id: 2600822,
- created_at: "2018-05-31T15:15:34+02:00",
- data01: "",
- data02: "",
- data03: "",
- delivery_date_id: null,
- has_custom_fields: false,
- has_discounts: false,
- has_matrix: false,
- hits: 0,
- hs_code: null,
- id: 72660113,
- image_id: null,
- is_visible: false,
- price_excl: 33.0165,
- price_incl: 39.95,
- price_old_excl: 0,
- price_old_incl: 0,
- product_set_id: null,
- product_type_id: null,
- search_context: "123 456 789",
- shop_id: 252449,
- sku: "789",
- supplier_id: 555236,
- updated_at: "2018-05-31T15:15:34+02:00",
- variants_count: 1,
- visibility: "hidden",
- weight: 0,
- links: {
- first: ".json",
- last: ".json?page=70",
- prev: null,
- next: ".json?page=2",
- count: 3497,
- limit: 50,
- pages: 70
- }
- while url:
- with requests.Session() as session:
- post = session.post(login, data=payload)
- r = session.get(url)
- parsed = json.loads(r.text)
- for product in parsed['products']:
- print(product['id'], product['nl']['title'])
- url = 'https://example/admin/products' + parsed['links']['next']
- <script>
- var dataSet = []
- var wurl = ""
- tablex = $('#tablex').dataTable( {
- select: true,
- stateSave: true,
- colReorder: true,
- deferRender: true,
- "oLanguage": {"sSearch": "Filter:"},
- columns: [
- { title: "Number" },
- { title: "Client Name" },
- { title: "Opened" },
- { title: "Closed" },
- { title: "Worked" }
- ]
- } );
- function generate() {
- $.get(wurl, function( data ) {
- dataSet = data;
- tablex.fnDestroy();
- tablex = $('#tablex').dataTable( {
- data: dataSet,
- select: true,
- stateSave: true,
- colReorder: true,
- deferRender: true,
- "oLanguage": {"sSearch": "Filter:"},
- columns: [
- { title: "Number" },
- { title: "Client Name" },
- { title: "Opened"},
- { title: "Closed"},
- { title: "Worked"}
- ],
- } );
- });
- };
- $(document).ready(function() {
- wurl = '/api/getdata';
- generate()
- } );
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement