aardio扩展库 数据维格表api
By
jerryxjr1220
at 2021-09-06 • 0人收藏 • 3162人看过
维格表是新一代的关系数据库,通过“数据层-关系层-视图层”的结构赋予了表格更安全并且更广泛的用途。
官网地址:vika维格 - 多维表格首创者,支持API的新一代数据协作与项目管理工具
维格表支持导入和导出Excel,CSV等多种数据格式,同时也支持甘特图,列表视图等多种数据可视化。官网内建了非常多的各行业模板,目前公测阶段可免费使用。
本扩展库是利用http调用vika的api接口:
import console; import Vika; console.open() vika = Vika("替换为你的Auth_Token_ID") records = vika.getrecords("U7HFcLUmL2WTd48") //fields = vika.getfields("U7HFcLUmL2WTd48") //views = vika.getviews("U7HFcLUmL2WTd48") //nodes = vika.getnodes("U7HFcLUmL2WTd48") console.dump(records); //console.dump(fields); //console.dump(views); //console.dump(nodes); console.pause(true);
扩展库(目前还不完善,先挖个坑,以后再填)
import web; import web.json; class Vika { ctor (Auth_token) { import inet.http; this = inet.http(); this.headers = { Authorization = "Bearer "++Auth_token; ["Content-Type"] = "application/json"; ["user-agent"] = "Mozilla/5.0"; }; }; getrecords = function(datasheet_id_or_url){ import web.json; if inet.url.is(datasheet_id_or_url,0x0/*_URLIS_URL*/) { return web.json.parse(this.get(datasheet_id_or_url)); } else { return web.json.parse(this.get("https://api.vika.cn/fusion/v1/datasheets/dst"++datasheet_id_or_url++"/records")); } }; getfields = function(datasheet_id_or_url){ import web.json; if inet.url.is(datasheet_id_or_url,0x0/*_URLIS_URL*/) { return web.json.parse(this.get(datasheet_id_or_url)); } else { return web.json.parse(this.get("https://api.vika.cn/fusion/v1/datasheets/dst"++datasheet_id_or_url++"/fields")); } }; getviews = function(datasheet_id_or_url){ import web.json; if inet.url.is(datasheet_id_or_url,0x0/*_URLIS_URL*/) { return web.json.parse(this.get(datasheet_id_or_url)); } else { return web.json.parse(this.get("https://api.vika.cn/fusion/v1/datasheets/dst"++datasheet_id_or_url++"/views")); } }; getnodes = function(space_id_or_url){ import web.json; if inet.url.is(space_id_or_url,0x0/*_URLIS_URL*/) { return web.json.parse(this.get(space_id_or_url)); } else { return web.json.parse(this.get("https://api.vika.cn/fusion/v1/spaces/spc"++space_id_or_url++"/nodes")); } }; getsheetsinfo = function(space_id_or_url, node_id=""){ import web.json; if inet.url.is(space_id_or_url,0x0/*_URLIS_URL*/) { return web.json.parse(this.get(space_id_or_url)); } else { return web.json.parse(this.get("https://api.vika.cn/fusion/v1/spaces/spc"++space_id_or_url++"/nodes/"++node_id)); } }; }
23 个回复 | 最后更新于 2022-09-20
2021-09-07
#3
import web.rest.jsonLiteClient; class vika { ctor (AuthToken) { this = ..web.rest.jsonLiteClient(); this.defaultContentType = "application/json"; this.defaultUrlTemplate = "https://api.vika.cn/fusion/v1/datasheets/dst{DataSheetID}"; this.addHeaders = { Authorization: "Bearer "++ AuthToken; } this.http = this.api() }; getrecords = function(DataSheetID){ return this.http[DataSheetID].records.get(); }; getviews = function(DataSheetID){ return this.http[DataSheetID].views.get(); }; getfields = function(DataSheetID){ return this.http[DataSheetID].fields.get(); }; getnodes = function(NodesID){ return this.api("https://api.vika.cn/fusion/v1/spaces/spc{NodesID}")[NodesID].nodes.get() }; }
回复#3 @jacen :
果然更简洁了,赞!
2021-09-07
#4
添加一个过滤器
namespace vika{ filter = function(records, filter_list){ records = records.data.records; results = {} for _,record in records { var flg = true; for k,v in filter_list { if record.fields[k] != v { flg = false; break; } } if flg { ..table.push(results, record) } } return results; } }
调用的时候
import console; import vika; vk = vika("你的AuthToken") records = vk.getrecords("U7HFcLUmL2WTd48") res = vika.filter(records, {剧集="E1";}) console.dump(res); console.pause();
2021-09-07
#5
添加记录
class vika { ctor (AuthToken) { this = ..web.rest.jsonLiteClient(); this.defaultContentType = "application/json"; this.defaultUrlTemplate = "https://api.vika.cn/fusion/v1/datasheets/dst{DataSheetID}"; this.addHeaders = { Authorization: "Bearer "++ AuthToken; } this.http = this.api() }; getrecords = function(DataSheetID){ this.records = this.http[DataSheetID].records.get(); return this.records; }; getviews = function(DataSheetID){ this.views = this.http[DataSheetID].views.get(); return this.views; }; getfields = function(DataSheetID){ this.fields = this.http[DataSheetID].fields.get(); return this.fields; }; getnodes = function(NodesID){ this.nodes = this.api("https://api.vika.cn/fusion/v1/spaces/spc{NodesID}")[NodesID].nodes.get(); return this.nodes; }; addrecords = function(DataSheetID, sdata){ if type(sdata) == "string" { data = ..web.json.parse(sdata); } else { data = sdata; } if !data["records"] { dd = {records={};}; for _,d in data { ..table.push(dd.records, {fields=d;}); } } else { dd = data; } this.records = this.http[DataSheetID].records.post(..web.json.stringify(dd)); return this.records; } }
调用添加记录
data = { { 剧集= "E1", 状态= "已追", 播放地址= "https://www.adcmovies.com/play/159895-1-1.html" }; { 剧集= "E2", 状态= "已追", 播放地址= "https://www.adcmovies.com/play/159895-1-2.html" } } pres = vk.addrecords("U7HFcLUmL2WTd48", data)
2021-09-08
#9
插一个题外话,对于字符串的排序一般是怎么做的?
我用了md5,提取数字再比较,感觉很怪。。。
..table.sort(tab, function(row){ a, b = row[cloumn], owner[cloumn] md5a = ..crypt.md5(a); md5b = ..crypt.md5(b); ta = ..string.matches(tostring(md5a),"\d") tb = ..string.matches(tostring(md5b),"\d") tta, ttb = {}, {} for _,t in ta {..table.push(tta, t[1])} for _,t in tb {..table.push(ttb, t[1])} na = tonumber(..string.join(tta,'')) nb = tonumber(..string.join(ttb,'')) return na<nb; })
2021-09-08
#13
回复#13 @nlysh007 :
我这是listview排序里截取出来的一段代码
grid = win.ui.grid(mainForm.listview); grid.onSortColumn = function(cloumn,desc){ var tab = ..table.clone(mainForm.listview.items); ..table.sort(tab, function(row){ return row[cloumn]<owner[cloumn]; }) if desc {..table.reverse(tab)}; mainForm.listview.items = tab; return true; }
这样已经能实现排序了。
回复#6 @jerryxjr1220 :
我试着写了DELETE方法,发现写不好。官方说明里是这样的:
curl -X DELETE "https://api.vika.cn/fusion/v1/datasheets/dstu5Pv8oTgTlU5xQJ/records?recordIds=recC7H4a2jRO7&recordIds=recmhsNfRUQ3t" \ -H "Authorization: Bearer _替换成你的API_Token_"
我写成这样:
delete = function(DataSheetID,recordId){ result = this.api("https://api.vika.cn/fusion/v1/datasheets/"+tostring(DataSheetID)+"/records?recordIds="+tostring(recordId),'delete'); return result; }
但实际上删除不了。
还以为一个很奇怪的问题,试着增加两条记录,提示400错误:
单次请求修改/删除/新增的记录不能超过 10 条
登录后方可回帖
支持下,持续关注