Advertisement
Misipuk

backend_old7

Jul 20th, 2021
1,545
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. export async function get_tv_data() {
  47.     var flagok = false
  48.     let r_json = await wixFetch.fetch("https://5eaf48843844.ngrok.io/tvpricing?date=20%2F07%2F2021", {"method": "get"})
  49.     .then( (httpResponse) => {
  50.     if (httpResponse.ok) {
  51.         flagok = true
  52.         //console.log(httpResponse.json())
  53.         return httpResponse.json();
  54.     } else {
  55.         return Promise.reject("Fetch did not succeed");
  56.     }
  57.     } )
  58.     .catch(err => console.log(err))
  59.  
  60.     console.log("Hello")
  61.     console.log(r_json)
  62.     console.log(r_json.length)
  63.     //console.log(JSON.parse(r_json)[0])
  64.  
  65.     //r_json = JSON.parse(r_json)
  66.  
  67.     //let toInsert =
  68.    
  69.     if (flagok){
  70.         //parse_df(r_json)
  71.         for(let i = 0; i<r_json.length; i++) {
  72.             await wixData.insert("tv_data", {
  73.                     title: i.toString(),
  74.                     df_tv_10: r_json[i][0],
  75.                     df_tv_30: r_json[i][1],
  76.                     df_tv_60: r_json[i][2],
  77.                     ag_table: r_json[i][3],
  78.                 })
  79.         }
  80.     }
  81.         //await wixData.insert("hv_data", {call1: r_json})
  82.         //const res = await wixData.query('opt_data').limit(200).find();
  83.         //const data = res.items;
  84.         //console.log(data[0]["call1"])
  85.    
  86. }
  87.  
  88.  
  89. export async function getcorrdata() {
  90.     var flagok = false
  91.     let r_json = await wixFetch.fetch("https://5eaf48843844.ngrok.io/dfcorr", {"method": "get"})
  92.     .then( (httpResponse) => {
  93.     if (httpResponse.ok) {
  94.         flagok = true
  95.         //console.log(httpResponse.json())
  96.         return httpResponse.json();
  97.     } else {
  98.         return Promise.reject("Fetch did not succeed");
  99.     }
  100.     } )
  101.     .catch(err => console.log(err))
  102.  
  103.     console.log("Hello")
  104.     console.log(r_json)
  105.     console.log(r_json.length)
  106.     //console.log(JSON.parse(r_json)[0])
  107.  
  108.     //r_json = JSON.parse(r_json)
  109.  
  110.     //let toInsert =
  111.     if (flagok){
  112.         //parse_df(r_json)
  113.         await wixData.insert("corr_data", {
  114.                     df_hours: r_json[0],
  115.                     df_days: r_json[1],
  116.                     df_weeks: r_json[2],
  117.                     df_months: r_json[3],
  118.         })
  119.         //await wixData.insert("hv_data", {call1: r_json})
  120.         //const res = await wixData.query('opt_data').limit(200).find();
  121.         //const data = res.items;
  122.         //console.log(data[0]["call1"])
  123.     }
  124. }
  125.  
  126.  
  127. export async function gethvdata() {
  128.     var flagok = false
  129.     let r_json = await wixFetch.fetch("https://5eaf48843844.ngrok.io/dfhv", {"method": "get"})
  130.     .then( (httpResponse) => {
  131.     if (httpResponse.ok) {
  132.         flagok = true
  133.         //console.log(httpResponse.json())
  134.         return httpResponse.json();
  135.     } else {
  136.         return Promise.reject("Fetch did not succeed");
  137.     }
  138.     } )
  139.     .catch(err => console.log(err))
  140.  
  141.     console.log(r_json)
  142.     console.log(r_json.length)
  143.    
  144.    
  145.     if (flagok){
  146.        
  147.         await wixData.insert("hv_data", {"jsondata": r_json})
  148.         //const res = await wixData.query('opt_data').limit(200).find();
  149.         //const data = res.items;
  150.         //console.log(data[0]["call1"])
  151.     }
  152. }
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement