Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 95 lines (60 sloc) 2.619 kb
d1d9664 @mislav more examples in readme
authored
1 # Filthy → gorgeous
2
3 Convert between formats.
4
4025516 @mislav ♫ cause you're filthy, oooh and I'm gorgeous ♪
authored
5 Usage:
6
7 gorgeous [-i] [-F <in-format>] [-T <out-format>] [-q <query>] [-o <destination>] FILE ...
8
d1d9664 @mislav more examples in readme
authored
9 This utility converts data between different formats.
4025516 @mislav ♫ cause you're filthy, oooh and I'm gorgeous ♪
authored
10 Formats are one of: json, xml, yaml, ruby, email, url
11
12 Input can be read from STDIN as well as files given on the command-line.
13
14 Options:
15
16 -i Convert file in-place
17 -F Input format
18 -T Output format
19 -q Query selector in format similar to XPath (see below)
20 -o Write output to file instead of STDOUT
21
22 Query format:
23
24 "/items/comments[1]/text" -- 2nd comment body of each item
25 "/items[-1]/user/full_name" -- name of user for last item
26 "//user/username" -- usernames of all users anywhere in the document
d1d9664 @mislav more examples in readme
authored
27
28 ## Prerequisites
29
30 It's recommended that you install all of these ruby libraries. They are only loaded when processing specific formats.
31
10c6e67 @mislav more details about optional dependencies
authored
32 * **nokogiri** for HTML/XML
33 * **yajl-ruby** or **json** for JSON (for Ruby < 1.9)
d1d9664 @mislav more examples in readme
authored
34 * **activesupport** (for various stuff)
35 * **rack** for url
36 * **mail** for email
37
38 All together now:
39
40 $ gem install nokogiri yajl-ruby activesupport rack mail
41
42 ## Examples
43
44 Pipe in standard input:
45
46 # auto-detects input as being JSON, displays prettified output:
47 $ curl -s api.twitter.com/1/statuses/show/40453487309361153.json | gorgeous
48
49 # covert from JSON to YAML
50 $ curl -s <url> | gorgeous -T yaml
51
52 # extract Twitter avatar from tweet as text
53 $ curl -s <url> | gorgeous -T txt -q /user/profile_image_url
54
55 Prettify a file in place:
56
57 # auto-detects format by extension, prettifies and overwrites the file:
58 $ gorgeous -i some-data.json
59
60 # convert some data to YAML
61 $ gorgeous -i -F json -T yaml some-data
62
63 Prettify some HTML (gorgeous calls it "xml"):
64
65 $ curl -s www.1112.net/lastpage.html | gorgeous -F xml
66
67 Prettify content in clipboard (on a Mac):
68
69 $ pbpaste | gorgeous | pbcopy
70
71 # convert from YAML to ruby format and copy to clipboard
72 $ gorgeous fixture.yml -T ruby | pbcopy
73
74 Parse query strings and URL-encoded POST payloads:
75
76 $ echo 'sourceid=chrome&ie=UTF-8&q=filthy+gorgeous' | gorgeous -T yaml
77 ---
78 sourceid: chrome
79 q: filthy gorgeous
80 ie: UTF-8
81
82 Parse emails:
83
84 # extract prettified HTML part of the email:
85 $ cat email.raw | gorgeous -F email -T xml
86
87 # extract decoded text part of the email:
88 $ cat email.raw | gorgeous -F email -T txt
89
90 # get email headers as JSON:
91 $ cat email.raw | gorgeous -F email -T json
92
93 # get only the email subject:
94 $ cat email.raw | gorgeous -F email -T txt -q /subject
Something went wrong with that request. Please try again.