-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
115 lines (95 loc) · 3.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//import axios from 'axios'
const fs = require("fs");
const axios=require('axios')
function timestampToTime(timestamp) {
var date = new Date(timestamp*1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '-';
var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
var D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate());
//var D = date.getDate() + ' ';
/* var h = date.getHours() + ':';
var m = date.getMinutes() + ':';
var s = date.getSeconds(); */
// Log(Y+M+D)
return Y+M+D;
}
let gettoday=(coinname)=>{
let today=new Date().getTime()
//today=Math.floor(today/1000)
let last=Math.floor(today/1000)
// console.log(today)
//console.log(last)
// let test= "https://api.mytokenapi.com/currency/kline?com_id="+coinname+"_usdt&symbol="+coinname+"&anchor=USDT&time="+last+"&market_id=338&period=1d×tamp=1674739035146&code=ebc161c4c01e448626c3cc30518009d6&platform=web_pc&v=1.0.0&language=en_US&legal_currency=USD"
// let test= "https://getyestoday.netlify.app/currency/kline?com_id="+coinname+"_usdt&symbol="+coinname+"&anchor=USDT&time="+last+"&market_id=338&period=1d×tamp=1674739035146&code=ebc161c4c01e448626c3cc30518009d6&platform=web_pc&v=1.0.0&language=en_US&legal_currency=USD"
let test= "https://api.mytokenapi.com/currency/"+"kline?com_id="+coinname+"_usdt&symbol="+coinname+"&anchor=USDT&time="+last+"&market_id=338&period=1d×tamp=1674739035146&code=ebc161c4c01e448626c3cc30518009d6&platform=web_pc&v=1.0.0&language=en_US&legal_currency=USD"
// console.log(test)
return test
}
let getlittledata=(klinedata)=>{
let arr=[]
for(let i=0;i<9;i++){
klinedata[i].time=timestampToTime(klinedata[i].time)
arr.push(klinedata[i])
}
return arr
}
function getcoindata(coinname){
return new Promise((resolve, reject) =>{
const config = {
headers:{
'Content-Type': 'application/json; charset=utf-8',
'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
}
};
axios
.get(gettoday(coinname),config)
.then(response => {
let kdata = getlittledata(response.data.data.kline)
//console.log(gettoday('btc'))
//console.log(kdata)
resolve(kdata)
})
.catch(function (error) { // 请求失败处理
console.log(error);
reject(error)
});
})
}
function postdata(url,updata){
return new Promise((resolve, reject) =>{
const config = {
headers:{
"Authorization": "Bearer"+'secret',
"accept": "application/json",
"Notion-Version": "2022-06-28",
"content-type": "application/json"
}
}
axios
.post(url,config,updata)
.then(response => {
//console.log(gettoday('btc'))
//console.log(kdata)
resolve(response)
})
.catch(function (error) { // 请求失败处理
console.log(error);
reject(error)
});
})
}
async function test(){
/* let testdata=await getcoindata('eth')
console.log(testdata)
testdata=await getcoindata('btc')
console.log(testdata) */
let querydata= {
/* "property": "time",
"contains": "20230211" */
/* "page_size":100 */
}
let backdata=await postdata("https://api.notion.com/v1/databases/{}/query",querydata)
console.log(backdata)
}
//
test()