Random Vim Regex
CampusBooks API
This will turn the tables at http://partners.campusbooks.com/api.php?pl_id=2496 into machine readable json
:%s/"/\"/g :%s/(\w+)\s(.)/{\r key: "\1",\r description: "\2"\r},/
From this:
isbn The thirteen digit ISBN for this offer
merchant_id A numeric merchant ID (Note, this value may be signed)
merchant_name The Name of the merchant (looked up from the defined constants)
merchant_image URL of the merchant logo
To this:
values = [
{
key: "isbn",
description: "The thirteen digit ISBN for this offer"
},
{
key: "merchant_id",
description: "A numeric merchant ID (Note, this value may be signed)"
},
{
key: "merchant_name",
description: "The Name of the merchant (looked up from the defined constants)"
},
{
key: "merchant_image",
description: "URL of the merchant logo"
}
]
Formatting XML in a JSON string
:%s/"/\"/g :%s/</</g :%s/>\n/>" +\r/ :%s/>/>/g :%s/^/"/
From this:
<merchant>
<merchant_id>108</merchant_id>
<merchant_image>http://www.campusbooks.com/images/markets/firstclassbooks.gif</merchant_iamge>
<name>First Class Books</name>
<notes>Free shipping via USPS or FedEx. Books must be ....</notes>
<prices>
<price condition="new">13.55</price>
<price condition="used">13.55</price>
</prices>
<link> http://partners.campusbooks.com/link.php?params=b3...</link>
</merchant>
To this:
example: "<pre><code>" +
"<merchant>" +
" <merchant_id>108</merchant_id>" + " <merchant_image>http://www.campusbooks.com/images/markets/firstclassbooks.gif</merchant_iamge>" + " <name>First Class Books</name>" +
" <notes>Free shipping via USPS or FedEx. Books must be ....</notes>" +
" <prices>" +
" <price condition=\"new\">13.55</price>" +
" <price condition=\"used\">13.55</price>" +
" </prices>" +
" <link> http://partners.campusbooks.com/link.php?params=b3...</link>" +
"</merchant>" +
"</code></pre>"
Was this useful to you? Share it!
blog comments powered by Disqus
