Advertisement
Misipuk

backend_old3

Jul 20th, 2021
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import wixData from 'wix-data';
  2. import wixFetch from 'wix-fetch';
  3.  
  4. export async function getoptdata() {
  5.     var flagok = false
  6.     let r_json = await wixFetch.fetch("https://5eaf48843844.ngrok.io/optprice", {"method": "get"})
  7.     .then( (httpResponse) => {
  8.     if (httpResponse.ok) {
  9.         flagok = true
  10.         //console.log(httpResponse.json())
  11.         return httpResponse.json();
  12.     } else {
  13.         return Promise.reject("Fetch did not succeed");
  14.     }
  15.     } )
  16.     .catch(err => console.log(err))
  17.  
  18.     console.log("Hello")
  19.     console.log(r_json)
  20.     console.log(r_json.length)
  21.     //console.log(JSON.parse(r_json)[0])
  22.  
  23.     //r_json = JSON.parse(r_json)
  24.  
  25.     //let toInsert =
  26.     if (flagok){
  27.         //parse_df(r_json)
  28.         for(let i = 0; i<r_json.length; i++) {
  29.             await wixData.insert("opt_data", {
  30.                     title: i.toString(),
  31.                     call1: r_json[i][0],
  32.                     call2: r_json[i][1],
  33.                     call3: r_json[i][2],
  34.                     put1: r_json[i][3],
  35.                     put2: r_json[i][4],
  36.                     put3: r_json[i][5]
  37.                 })
  38.         }
  39.         //await wixData.insert("hv_data", {call1: r_json})
  40.         //const res = await wixData.query('opt_data').limit(200).find();
  41.         //const data = res.items;
  42.         //console.log(data[0]["call1"])
  43.     }
  44. }
  45.  
  46.  
  47. export async function gethvdata() {
  48.     var flagok = false
  49.     let r_json = await wixFetch.fetch("https://5eaf48843844.ngrok.io/dfhv", {"method": "get"})
  50.     .then( (httpResponse) => {
  51.     if (httpResponse.ok) {
  52.         flagok = true
  53.         //console.log(httpResponse.json())
  54.         return httpResponse.json();
  55.     } else {
  56.         return Promise.reject("Fetch did not succeed");
  57.     }
  58.     } )
  59.     .catch(err => console.log(err))
  60.  
  61.     console.log(r_json)
  62.     console.log(r_json.length)
  63.    
  64.    
  65.     if (flagok){
  66.        
  67.         await wixData.insert("hv_data", {"jsondata": r_json})
  68.         //const res = await wixData.query('opt_data').limit(200).find();
  69.         //const data = res.items;
  70.         //console.log(data[0]["call1"])
  71.     }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement