Advertisement
Misipuk

backend_old1

Jul 20th, 2021
904
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.                 })
  35.         }
  36.         //await wixData.insert("hv_data", {call1: r_json})
  37.         //const res = await wixData.query('opt_data').limit(200).find();
  38.         //const data = res.items;
  39.         //console.log(data[0]["call1"])
  40.     }
  41. }
  42.  
  43.  
  44. export async function gethvdata() {
  45.     var flagok = false
  46.     let r_json = await wixFetch.fetch("https://5eaf48843844.ngrok.io/dfhv", {"method": "get"})
  47.     .then( (httpResponse) => {
  48.     if (httpResponse.ok) {
  49.         flagok = true
  50.         //console.log(httpResponse.json())
  51.         return httpResponse.json();
  52.     } else {
  53.         return Promise.reject("Fetch did not succeed");
  54.     }
  55.     } )
  56.     .catch(err => console.log(err))
  57.  
  58.     console.log(r_json)
  59.     console.log(r_json.length)
  60.    
  61.    
  62.     if (flagok){
  63.        
  64.         await wixData.insert("hv_data", {"jsondata": r_json})
  65.         //const res = await wixData.query('opt_data').limit(200).find();
  66.         //const data = res.items;
  67.         //console.log(data[0]["call1"])
  68.     }
  69. }
  70.  
  71.  
  72. export async function test(){
  73.     const res = await wixData.query('hv_data').find();
  74.     //var json = JSON.parse(res.items[0]["jsondata"])
  75.     console.log(res.items)
  76.     var json = res.items[0]["jsondata"]
  77.     var n_json = JSON.parse(json)
  78.     console.log(n_json)
  79. }
  80.  
  81.  
  82. function parse_df(r_json){
  83.     if (r_json) {
  84.         let hv_arr = [];
  85.         for (let key in r_json) {
  86.             //console.log(r_json[key])
  87.             let temp_arr = []
  88.             for (let name in r_json[key]){
  89.                 //console.log(name)
  90.                 temp_arr.push(r_json[key][name])
  91.             }
  92.             //console.log(temp_arr)
  93.             hv_arr.push(temp_arr)
  94.         }
  95.         console.log(hv_arr)
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement