I have almost the same problem.
I'm using the following syntax:
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
and I get this :
{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}}}}}
My problem is : I'm a newbie and I just want to get tags that have a confidence greater than 12. I would like to get something like this :
symbol,art,graphic,design,icon,cartoon,drawing,decoration,[...]retro
What should I add at the end of my syntax ?
Thx for your help!
Please try this, I added comments to the lines, the result is in the variable filteredTags which is a list of strings.
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
First off I am new to Powershell, as in this is my first ever attempt. I'm doing the I can program in other languages so I can hack through this project. I have spent a few days now trying to solve this one, and I know is something stupid. I'm just stuck.
# Insert into master table
$query = "INSERT INTO ``master``(``diff``, ``key``) VALUES ('$diff', '$key')"
Invoke-MySqlQuery -Query $query
$query
This works fine the test output displays:
INSERT INTO `master`(`diff`, `key`) VALUES ('248', 'k000002143200000000000000680006080005500900030082670009461000500000091000000000000')
It also inputs into the MySQL DB just fine.
This following the exact same format is not working for me. Like I said at the top, I know it is some stupid formatting thing I'm missing.
# Insert into answers table
$query = "INSERT INTO ``puzzles``(``id``, ``p1``, ``p2``, ``p3``, ``p4``, ``p5``, ``p6``, ``p7``, ``p8``, ``p9``, ``p10``, ``p11``, ``p12``, ``p13``, ``p14``, ``p15``, ``p16``, ``p17``, ``p18``, ``p19``, ``p20``, ``p21``, ``p22``, ``p23``, ``p24``, ``p25``, ``p26``, ``p27``, ``p28``, ``p29``, ``p30``, ``p31``, ``p32``, ``p33``, ``p34``, ``p35``, ``p36``, ``p37``, ``p38``, ``p39``, ``p40``, ``p41``, ``p42``, ``p43``, ``p44``, ``p45``, ``p46``, ``p47``, ``p48``, ``p49``, ``p50``, ``p51``, ``p52``, ``p53``, ``p54``, ``p55``, ``p56``, ``p57``, ``p58``, ``p59``, ``p60``, ``p61``, ``p62``, ``p63``, ``p64``, ``p65``, ``p66``, ``p67``, ``p68``, ``p69``, ``p70``, ``p71``, ``p72``, ``p73``, ``p74``, ``p75``, ``p76``, ``p77``, ``p78``, ``p79``, ``p80``, ``p81``) VALUES ('$id', '$p[0]', '$p[1]', '$p[2]', '$p[3]', '$p[4]', '$p[5]', '$p[6]', '$p[7]', '$p[8]', '$p[9]', '$p[10]', '$p[11]', '$p[12]', '$p[13]', '$p[14]', '$p[15]', '$p[16]', '$p[17]', '$p[18]', '$p[19]', '$p[20]', '$p[21]', '$p[22]', '$p[23]', '$p[24]', '$p[25]', '$p[26]', '$p[27]', '$p[28]', '$p[29]', '$p[30]', '$p[31]', '$p[32]', '$p[33]', '$p[34]', '$p[35]', '$p[36]', '$p[37]', '$p[38]', '$p[39]', '$p[40]', '$p[41]', '$p[42]', '$p[43]', '$p[44]', '$p[45]', '$p[46]', '$p[47]', '$p[48]', '$p[49]', '$p[50]', '$p[51]', '$p[52]', '$p[53]', '$p[54]', '$p[55]', '$p[56]', '$p[57]', '$p[58]', '$p[59]', '$p[60]', '$p[61]', '$p[62]', '$p[63]', '$p[64]', '$p[65]', '$p[66]', '$p[67]', '$p[68]', '$p[69]', '$p[70]', '$p[71]', '$p[72]', '$p[73]', '$p[74]', '$p[75]', '$p[76]', '$p[77]', '$p[78]', '$p[79]', '$p[80]')"
$query
$p[0]
$p[1]
$p[2]
$p[3]
$p[4]
$p[5]
Invoke-MySqlQuery -Query $query
This is the output I get on one of the runs:
INSERT INTO `puzzles`(`id`, `p1`, `p2`, `p3`, `p4`, `p5`, `p6`, `p7`, `p8`, `p9`, `p10`, `p11`, `p12`, `p13`, `p14`, `p15`, `p16`, `p17`, `p
18`, `p19`, `p20`, `p21`, `p22`, `p23`, `p24`, `p25`, `p26`, `p27`, `p28`, `p29`, `p30`, `p31`, `p32`, `p33`, `p34`, `p35`, `p36`, `p37`, `p
38`, `p39`, `p40`, `p41`, `p42`, `p43`, `p44`, `p45`, `p46`, `p47`, `p48`, `p49`, `p50`, `p51`, `p52`, `p53`, `p54`, `p55`, `p56`, `p57`, `p
58`, `p59`, `p60`, `p61`, `p62`, `p63`, `p64`, `p65`, `p66`, `p67`, `p68`, `p69`, `p70`, `p71`, `p72`, `p73`, `p74`, `p75`, `p76`, `p77`, `p
78`, `p79`, `p80`, `p81`) VALUES ('2596', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[0]', '000002143
200000000000000680006080005500900030082670009461000500000091000000000000[1]', '0000021432000000000000006800060800055009000300826700094610005
00000091000000000000[2]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[3]', '0000021432000000000000006
80006080005500900030082670009461000500000091000000000000[4]', '00000214320000000000000068000608000550090003008267000946100050000009100000000
0000[5]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[6]', '00000214320000000000000068000608000550090
0030082670009461000500000091000000000000[7]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[8]', '00000
2143200000000000000680006080005500900030082670009461000500000091000000000000[9]', '000002143200000000000000680006080005500900030082670009461
000500000091000000000000[10]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[11]', '0000021432000000000
00000680006080005500900030082670009461000500000091000000000000[12]', '0000021432000000000000006800060800055009000300826700094610005000000910
00000000000[13]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[14]', '00000214320000000000000068000608
0005500900030082670009461000500000091000000000000[15]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[1
6]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[17]', '000002143200000000000000680006080005500900030
082670009461000500000091000000000000[18]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[19]', '0000021
43200000000000000680006080005500900030082670009461000500000091000000000000[20]', '0000021432000000000000006800060800055009000300826700094610
00500000091000000000000[21]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[22]', '00000214320000000000
0000680006080005500900030082670009461000500000091000000000000[23]', '00000214320000000000000068000608000550090003008267000946100050000009100
0000000000[24]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[25]', '000002143200000000000000680006080
005500900030082670009461000500000091000000000000[26]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[27
]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[28]', '0000021432000000000000006800060800055009000300
82670009461000500000091000000000000[29]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[30]', '00000214
3200000000000000680006080005500900030082670009461000500000091000000000000[31]', '00000214320000000000000068000608000550090003008267000946100
0500000091000000000000[32]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[33]', '000002143200000000000
000680006080005500900030082670009461000500000091000000000000[34]', '000002143200000000000000680006080005500900030082670009461000500000091000
000000000[35]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[36]', '0000021432000000000000006800060800
05500900030082670009461000500000091000000000000[37]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[38]
', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[39]', '00000214320000000000000068000608000550090003008
2670009461000500000091000000000000[40]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[41]', '000002143
200000000000000680006080005500900030082670009461000500000091000000000000[42]', '000002143200000000000000680006080005500900030082670009461000
500000091000000000000[43]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[44]', '0000021432000000000000
00680006080005500900030082670009461000500000091000000000000[45]', '0000021432000000000000006800060800055009000300826700094610005000000910000
00000000[46]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[47]', '00000214320000000000000068000608000
5500900030082670009461000500000091000000000000[48]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[49]'
, '000002143200000000000000680006080005500900030082670009461000500000091000000000000[50]', '000002143200000000000000680006080005500900030082
670009461000500000091000000000000[51]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[52]', '0000021432
00000000000000680006080005500900030082670009461000500000091000000000000[53]', '0000021432000000000000006800060800055009000300826700094610005
00000091000000000000[54]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[55]', '00000214320000000000000
0680006080005500900030082670009461000500000091000000000000[56]', '00000214320000000000000068000608000550090003008267000946100050000009100000
0000000[57]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[58]', '000002143200000000000000680006080005
500900030082670009461000500000091000000000000[59]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[60]',
'000002143200000000000000680006080005500900030082670009461000500000091000000000000[61]', '0000021432000000000000006800060800055009000300826
70009461000500000091000000000000[62]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[63]', '00000214320
0000000000000680006080005500900030082670009461000500000091000000000000[64]', '00000214320000000000000068000608000550090003008267000946100050
0000091000000000000[65]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[66]', '000002143200000000000000
680006080005500900030082670009461000500000091000000000000[67]', '000002143200000000000000680006080005500900030082670009461000500000091000000
000000[68]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[69]', '0000021432000000000000006800060800055
00900030082670009461000500000091000000000000[70]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[71]',
'000002143200000000000000680006080005500900030082670009461000500000091000000000000[72]', '00000214320000000000000068000608000550090003008267
0009461000500000091000000000000[73]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[74]', '000002143200
000000000000680006080005500900030082670009461000500000091000000000000[75]', '000002143200000000000000680006080005500900030082670009461000500
000091000000000000[76]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[77]', '0000021432000000000000006
80006080005500900030082670009461000500000091000000000000[78]', '0000021432000000000000006800060800055009000300826700094610005000000910000000
00000[79]', '000002143200000000000000680006080005500900030082670009461000500000091000000000000[80]')
0
0
0
0
0
2
In the $query variable the $p[X] does not work like the $p[X] below. It's spitting out the entire array. Obviously it's not working when it sends it to MySQL, I get the ID correct and that's it.
Thank you all for the help in advance, thumping my head on the keyboard hurts after awhile!
Ian
Bonus question! Any tips on this would be great as well. Any of the 0s don't need to be there, I actually want them as NULL. Any tips on a clean way to do that would be wonderful. Full disclosure I have not even looked into this part yet!
EDIT - In response to #Mathias R. Jessen
I removed all the other code not having to do with $p, to make it easy on the eyes.
# Set the key variable
$key = (Get-Content Puzzles.txt)[$loop] # ....73.146...8.......6......5..2..8.8..5.9..1.923..........273.........8..3..1.46 #Extreme
$key = $key.Replace(".", "0") # 000073014600080000000600000050020080800509001092300000000002730000000008003001046 #Extreme
$key = -join('k', $key.Substring(0,81)) # k000073014600080000000600000050020080800509001092300000000002730000000008003001046
$check = (Invoke-MySqlQuery -Query "SELECT COUNT(*) FROM ``master`` WHERE ``key`` = '$key'")
$check = $check.'COUNT(*)'
# Check in master table if key exists, i.e. not a new puzzle
IF ($check -eq 0) {
$p = $key.Substring(1,81) # 000073014600080000000600000050020080800509001092300000000002730000000008003001046
# Insert into answers table
$query = "INSERT INTO ``puzzles``(``id``, ``p1``, ``p2``, ``p3``, ``p4``, ``p5``, ``p6``, ``p7``, ``p8``, ``p9``, ``p10``, ``p11``, ``p12``, ``p13``, ``p14``, ``p15``, ``p16``, ``p17``, ``p18``, ``p19``, ``p20``, ``p21``, ``p22``, ``p23``, ``p24``, ``p25``, ``p26``, ``p27``, ``p28``, ``p29``, ``p30``, ``p31``, ``p32``, ``p33``, ``p34``, ``p35``, ``p36``, ``p37``, ``p38``, ``p39``, ``p40``, ``p41``, ``p42``, ``p43``, ``p44``, ``p45``, ``p46``, ``p47``, ``p48``, ``p49``, ``p50``, ``p51``, ``p52``, ``p53``, ``p54``, ``p55``, ``p56``, ``p57``, ``p58``, ``p59``, ``p60``, ``p61``, ``p62``, ``p63``, ``p64``, ``p65``, ``p66``, ``p67``, ``p68``, ``p69``, ``p70``, ``p71``, ``p72``, ``p73``, ``p74``, ``p75``, ``p76``, ``p77``, ``p78``, ``p79``, ``p80``, ``p81``) VALUES ('$id', '$p[0]', '$p[1]', '$p[2]', '$p[3]', '$p[4]', '$p[5]', '$p[6]', '$p[7]', '$p[8]', '$p[9]', '$p[10]', '$p[11]', '$p[12]', '$p[13]', '$p[14]', '$p[15]', '$p[16]', '$p[17]', '$p[18]', '$p[19]', '$p[20]', '$p[21]', '$p[22]', '$p[23]', '$p[24]', '$p[25]', '$p[26]', '$p[27]', '$p[28]', '$p[29]', '$p[30]', '$p[31]', '$p[32]', '$p[33]', '$p[34]', '$p[35]', '$p[36]', '$p[37]', '$p[38]', '$p[39]', '$p[40]', '$p[41]', '$p[42]', '$p[43]', '$p[44]', '$p[45]', '$p[46]', '$p[47]', '$p[48]', '$p[49]', '$p[50]', '$p[51]', '$p[52]', '$p[53]', '$p[54]', '$p[55]', '$p[56]', '$p[57]', '$p[58]', '$p[59]', '$p[60]', '$p[61]', '$p[62]', '$p[63]', '$p[64]', '$p[65]', '$p[66]', '$p[67]', '$p[68]', '$p[69]', '$p[70]', '$p[71]', '$p[72]', '$p[73]', '$p[74]', '$p[75]', '$p[76]', '$p[77]', '$p[78]', '$p[79]', '$p[80]')"
Invoke-MySqlQuery -Query $query
}
You need to use the subexpression operator $() to evaluate the collection at that index during string interpolation. Without this operator, the content of your entire collection is being printed, as well as your literal index syntax.
Your first example works as expected because you're only interpolating simple variables, without doing any additional work to them.
Here's a simple example from the command line:
C:\> $arr = 1,2,3,4
Outside of a string:
C:\> $arr[0]
1
During string interpolation, without the subexpression operator:
C:\> "$arr[0]"
1 2 3 4[0]
During string interpolation, with the subexpression operator:
C:\> "$($arr[0])"
1
This means that your example would become something like this:
...VALUES ('$id', '$($p[0])', '$($p[1])'...
Note that $id is working correctly because it is a simple variable. You only need to use the subexpression operator for additional work like evaluating indexes, properties, etc.
This concept is also sometimes called variable expansion, if you would like to research further.