Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wixData from 'wix-data';
- import wixFetch from 'wix-fetch';
- export async function getoptdata() {
- var flagok = false
- let r_json = await wixFetch.fetch("https://5eaf48843844.ngrok.io/optprice", {"method": "get"})
- .then( (httpResponse) => {
- if (httpResponse.ok) {
- flagok = true
- //console.log(httpResponse.json())
- return httpResponse.json();
- } else {
- return Promise.reject("Fetch did not succeed");
- }
- } )
- .catch(err => console.log(err))
- console.log("Hello")
- console.log(r_json)
- console.log(r_json.length)
- //console.log(JSON.parse(r_json)[0])
- //r_json = JSON.parse(r_json)
- //let toInsert =
- if (flagok){
- //parse_df(r_json)
- for(let i = 0; i<r_json.length; i++) {
- await wixData.insert("opt_data", {
- title: i.toString(),
- call1: r_json[i][0],
- call2: r_json[i][1],
- call3: r_json[i][2]
- })
- }
- //await wixData.insert("hv_data", {call1: r_json})
- //const res = await wixData.query('opt_data').limit(200).find();
- //const data = res.items;
- //console.log(data[0]["call1"])
- }
- }
- export async function gethvdata() {
- var flagok = false
- let r_json = await wixFetch.fetch("https://5eaf48843844.ngrok.io/dfhv", {"method": "get"})
- .then( (httpResponse) => {
- if (httpResponse.ok) {
- flagok = true
- //console.log(httpResponse.json())
- return httpResponse.json();
- } else {
- return Promise.reject("Fetch did not succeed");
- }
- } )
- .catch(err => console.log(err))
- console.log(r_json)
- console.log(r_json.length)
- if (flagok){
- await wixData.insert("hv_data", {"jsondata": r_json})
- //const res = await wixData.query('opt_data').limit(200).find();
- //const data = res.items;
- //console.log(data[0]["call1"])
- }
- }
- export async function test(){
- const res = await wixData.query('hv_data').find();
- //var json = JSON.parse(res.items[0]["jsondata"])
- console.log(res.items)
- var json = res.items[0]["jsondata"]
- var n_json = JSON.parse(json)
- console.log(n_json)
- }
- function parse_df(r_json){
- if (r_json) {
- let hv_arr = [];
- for (let key in r_json) {
- //console.log(r_json[key])
- let temp_arr = []
- for (let name in r_json[key]){
- //console.log(name)
- temp_arr.push(r_json[key][name])
- }
- //console.log(temp_arr)
- hv_arr.push(temp_arr)
- }
- console.log(hv_arr)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement