使用applescript

时间:2017-11-12 12:53:49

标签: json string curl applescript

我有几乎相同的问题。 我使用以下语法:

set LINK to ("https://XXXXXXXXXXXXXXXXXXXX.com")
set api to ("XXXXXXXXXXXX")
set secret to ("XXXXXXXXXXX")

set RR to do shell script "curl -u '" & api & ":" & secret & "' https:/XXXXXXXurl='" & LINK & "'"

tell application "JSON Helper"
    set RRR to (read JSON from RR)
end tell

我得到了这个:

  

{results:{{tagging_id:缺失值,   图像: “https://XXXXXXXXXXXXXXXXX.com”,   标签:{{tag:“symbol”,置信度:26.962820053101},{tag:“art”,   信心:26.631685256958},{tag:“graphic”,   信心:26.29425239563},{tag:“design”,   信心:25.914730072022},{tag:“icon”,置信度:21.400810241699},   {tag:“cartoon”,置信度:20.534477233887},{tag:“drawing”,   信心:18.931232452393},{tag:“decoration”,   信心:18.834970474243},{tag:“silhouette”,   信心:17.404066085815},{tag:“shape”,   信心:14.910034179688},{tag:“element”,   信心:14.898452758789},{tag:“sign”,置信度:14.306094169617},   {tag:“ornament”,置信度:13.806978225708},{tag:“human”,   信心:13.510297775269},{tag:“black”,   信心:13.444707870483},{tag:“logo”,置信度:13.409428596497},   {tag:“pattern”,置信度:13.006916999817},{tag:“retro”,   信心:12.30048751831},{tag:“star”,置信度:11.705702781677},   {tag:“color”,置信度:11.694045066834},{tag:“card”,   信心:11.57892036438},{tag:“gold”,置信度:11.519770622253},   {tag:“banner”,置信度:11.03851890564},{tag:“heat”,   信心:10.58930683136},{tag:“blaze”,置信度:10.454214096069},   {tag:“circle”,置信度:10.329438209534},{tag:“power”,   信心:10.084959030151},{tag:“decorative”,   信心:10.032000541687},{tag:“bright”,   信心:10.019249916077},{tag:“orange”,置信度:9.9829454422},   {tag:“concepts”,置信度:9.782785415649},{tag:“style”,   信心:9.65638256073},{tag:“outline”,置信度:9.480903625488},   {tag:“character”,置信度:9.435729026794},{tag:“floral”,   信心:9.367718696594},{tag:“flower”,置信度:9.236577987671},   {tag:“heraldry”,置信度:9.019858360291},{tag:“curve”,   信心:8.756514549255},{tag:“love”,置信度:8.692363739014},   {tag:“colorful”,置信度:8.608165740967},{tag:“leaf”,   信心:8.568987846375},{tag:“3d”,置信度:8.527961730957},   {tag:“fire”,置信度:8.443150520325},{tag:“hand”,   信心:8.4037733078},{tag:“clip art”,置信度:8.348271369934},   {tag:“heart”,置信度:8.291186332703},{tag:“backdrop”,   信心:8.250628471375},{tag:“figure”,置信度:8.186657905579},   {tag:“person”,置信度:8.040968894958},{tag:“yellow”,   信心:7.957674980164},{tag:“colors”,置信度:7.941210269928},   {tag:“frame”,置信度:7.811089992523},{tag:“golden”,   信心:7.745839118958},{tag:“壁纸”,   信心:7.666860580444},{tag:“head”,置信度:7.567168235779},   {tag:“paisley”,置信度:7.478963375092},{tag:“vintage”,   信心:7.451002120972},{tag:“light”,置信度:7.361023902893},   {tag:“gorgeous”,置信度:7.328865528107},{tag:“fantasy”,   信心:7.22393655777},{tag:“cute”,置信度:7.183915138245},   {tag:“holiday”,置信度:7.175530433655},{tag:“science”,   信心:7.122048377991},{tag:“animal”,置信度:7.087336540222},   {tag:“spring”,置信度:7.072511672974},{tag:“medical”,   信心:7.06857919693}}}}}

我的问题是:我是新手,我只想获得信心大于12的标签。我想得到这样的东西:

  

符号,艺术,图形,设计,图标,动画,绘画,装饰,[...]逆

在语法结束时我应该添加什么?

谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

请尝试这个,我在行中添加了注释,结果在变量filteredTags中,这是一个字符串列表。

set resultDict to {results:{{tagging_id:missing value, image:"https://XXXXXXXXXXXXXXXXX.com", tags:{{tag:"symbol", confidence:26.962820053101}, {tag:"art", confidence:26.631685256958}, {tag:"graphic", confidence:26.29425239563}, {tag:"design", confidence:25.914730072022}, {tag:"icon", confidence:21.400810241699}, {tag:"cartoon", confidence:20.534477233887}, {tag:"drawing", confidence:18.931232452393}, {tag:"decoration", confidence:18.834970474243}, {tag:"silhouette", confidence:17.404066085815}, {tag:"shape", confidence:14.910034179688}, {tag:"element", confidence:14.898452758789}, {tag:"sign", confidence:14.306094169617}, {tag:"ornament", confidence:13.806978225708}, {tag:"human", confidence:13.510297775269}, {tag:"black", confidence:13.444707870483}, {tag:"logo", confidence:13.409428596497}, {tag:"pattern", confidence:13.006916999817}, {tag:"retro", confidence:12.30048751831}, {tag:"star", confidence:11.705702781677}, {tag:"color", confidence:11.694045066834}, {tag:"card", confidence:11.57892036438}, {tag:"gold", confidence:11.519770622253}, {tag:"banner", confidence:11.03851890564}, {tag:"heat", confidence:10.58930683136}, {tag:"blaze", confidence:10.454214096069}, {tag:"circle", confidence:10.329438209534}, {tag:"power", confidence:10.084959030151}, {tag:"decorative", confidence:10.032000541687}, {tag:"bright", confidence:10.019249916077}, {tag:"orange", confidence:9.9829454422}, {tag:"concepts", confidence:9.782785415649}, {tag:"style", confidence:9.65638256073}, {tag:"outline", confidence:9.480903625488}, {tag:"character", confidence:9.435729026794}, {tag:"floral", confidence:9.367718696594}, {tag:"flower", confidence:9.236577987671}, {tag:"heraldry", confidence:9.019858360291}, {tag:"curve", confidence:8.756514549255}, {tag:"love", confidence:8.692363739014}, {tag:"colorful", confidence:8.608165740967}, {tag:"leaf", confidence:8.568987846375}, {tag:"3d", confidence:8.527961730957}, {tag:"fire", confidence:8.443150520325}, {tag:"hand", confidence:8.4037733078}, {tag:"clip art", confidence:8.348271369934}, {tag:"heart", confidence:8.291186332703}, {tag:"backdrop", confidence:8.250628471375}, {tag:"figure", confidence:8.186657905579}, {tag:"person", confidence:8.040968894958}, {tag:"yellow", confidence:7.957674980164}, {tag:"colors", confidence:7.941210269928}, {tag:"frame", confidence:7.811089992523}, {tag:"golden", confidence:7.745839118958}, {tag:"wallpaper", confidence:7.666860580444}, {tag:"head", confidence:7.567168235779}, {tag:"paisley", confidence:7.478963375092}, {tag:"vintage", confidence:7.451002120972}, {tag:"light", confidence:7.361023902893}, {tag:"ornate", confidence:7.328865528107}, {tag:"fantasy", confidence:7.22393655777}, {tag:"cute", confidence:7.183915138245}, {tag:"holiday", confidence:7.175530433655}, {tag:"science", confidence:7.122048377991}, {tag:"animal", confidence:7.087336540222}, {tag:"spring", confidence:7.072511672974}, {tag:"medical", confidence:7.06857919693}}}}}

-- get the value for key `results`
set theResults to resultDict's results
-- check if the array is not empty
if (count theResults) = 0 then return
-- get the value for key `tags` of the first item of `theResults`
set theTags to theResults's first item's tags
-- create the list for the result
set filteredTags to {}
-- in the repeat loop get the value for key `confidence` and
-- add the tag to the result list if the value > 12
repeat with aTag in theTags
    if aTag's confidence > 12.0 then set end of filteredTags to aTag's tag
end repeat