6

I would like to get the result of this search and display the result in a notification or safari popup.

" set result to do shell script "curl https://www.binlist.net/json/" & cc without altering line endings" only have as a result the same value of the main query

-- Web site https://www.binlist.net
-- Get https://www.binlist.net/json/431940
set cc to the clipboard
set finalresult to do shell script "curl https://www.binlist.net/json/" & cc without altering line endings
set the clipboard to finalresult

display notification "result is " & finalresult

The result won't display as a notification so for now, its only set as clipboard Also the result is really raw can I clean that somehow ?

{\"bin\":\"431940\",\"brand\":\"VISA\",\"sub_brand\":\"\",\"country_code\":\"IE\",\"country_name\":\"Ireland\",\"bank\":\"BANK OF IRELAND\",\"card_type\":\"DEBIT\",\"card_category\":\"\",\"latitude\":\"53\",\"longitude\":\"-8\",\"query_time\":\"1.370709ms\"}""

Thanks.

4
  • Given your example JSON, what would you like to see displayed? Jan 12, 2016 at 15:14
  • I just ran your code with having set 431940 on the clipboard and the final result set back to the clipboard was exactly what I see if looking at binlist.net/json/431940 in Safari. So not sure what your issue is with formatting other the the results displayed in Script Editor e.g set the clipboard to "{\"bin\":\"431940\... the backslashes show there are not on the clipboard. Are you saying they are? Jan 12, 2016 at 15:22
  • Here is my result, I was wondering can I just keep "Visa" and "Ireland" and display in a notification : {"bin":"431940","brand":"VISA","sub_brand":"","country_code":"IE","country_name":"Ireland","bank":"BANK OF IRELAND","card_type":"DEBIT","card_category":"","latitude":"53","longitude":"-8","query_time":"651.384µs"}
    – Kevin
    Jan 12, 2016 at 15:27
  • Sorry but it is not clear, to me anyway, what you're asking in the last comment. Jan 12, 2016 at 15:50

1 Answer 1

5

You want the brand and the country_name from the JSON data, you can use a JSON parser.

Here is an example of parsing JSON in python

-- Get https://www.binlist.net/json/431940
set cc to the clipboard as string
set finalresult to do shell script "curl https://www.binlist.net/json/" & cc & "  |  /usr/bin/python -c 'import json, sys; obj=json.load(sys.stdin); print obj[\"brand\"],obj[\"country_name\"]' "
display notification "Result is " & finalresult --> "Result is VISA Ireland"
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .