Skip to content

Instantly share code, notes, and snippets.

@dgtized
Last active December 18, 2015 12:39
Show Gist options
  • Save dgtized/5784426 to your computer and use it in GitHub Desktop.
Save dgtized/5784426 to your computer and use it in GitHub Desktop.
[13 clgc@nocturnal ~/andy]$ ./to-csv.rb test.in
{"Name"=>"Richard Ruland", "Employee"=>nil, "Part-Time Status"=>nil, "Employee ID Number"=>"040807", "Home Address"=>"505 Westgate", "City"=>"U City", "State"=>"MO", "Zip Code"=>"63130", "Home/Mobile Phone Number"=>"727-2137", "License Plate#"=>"PB9 A8S", "State of license plate"=>"MO", "Make of vehicle"=>"Nissan", "Color of vehicle"=>"slate blue", "Primary Mode of Transportation to Campus"=>"walk Secondary Mode of", "Transportation (if applicable)"=>nil, "(Walk, Bike, Carpool/Vanpool, Metro Bus/Shuttle, MetroLink,"=>nil, "Motorcycle/Scooter, Off-Site Parking Permit, or specify other)"=>nil, "Employees and Campus Residents Only"=>nil, "Campus Box Number"=>"1122", "Campus Phone Extension"=>"4408"}
{"Name"=>"Jane Doe", "Student or Employee"=>"Employee", "Full-Time or Part-Time Status"=>"full time", "Employee/Student ID Number"=>"012365", "Home Address"=>"710 westgate", "City"=>"St Louis", "State"=>"MO", "Zip Code"=>"63130", "Home/Mobile Phone Number"=>"314-123-4567", "License Plate#"=>"mrg-143", "State of license plate"=>"MO", "Make of vehicle"=>"Toyota Camry", "Color of vehicle"=>"Blue", "Primary Mode of Transportation to Campus"=>"Metro bus and MetroLink", "Secondary Mode of Transportation (if applicable)"=>nil, "(Walk, Bike, Carpool/Vanpool, Metro Bus/Shuttle, MetroLink,"=>nil, "Motorcycle/Scooter, Off-Site Parking Permit, or specify other)"=>nil, "Employees and Campus Residents Only"=>nil, "Campus Box Number"=>"4321", "Campus Phone Extension"=>"5-1234"}
$ ./to-csv.rb test.in
---
Name: Richard Ruland
Employee:
Part-Time Status:
Employee ID Number: 040807
Home Address: 505 Westgate
City: U City
State: MO
Zip Code: '63130'
Home/Mobile Phone Number: 727-2137
License Plate#: PB9 A8S
State of license plate: MO
Make of vehicle: Nissan
Color of vehicle: slate blue
Primary Mode of Transportation to Campus: walk Secondary Mode of
Transportation (if applicable):
(Walk, Bike, Carpool/Vanpool, Metro Bus/Shuttle, MetroLink,:
Motorcycle/Scooter, Off-Site Parking Permit, or specify other):
Employees and Campus Residents Only:
Campus Box Number: '1122'
Campus Phone Extension: '4408'
---
Name: Jane Doe
Student or Employee: Employee
Full-Time or Part-Time Status: full time
Employee/Student ID Number: '012365'
Home Address: 710 westgate
City: St Louis
State: MO
Zip Code: '63130'
Home/Mobile Phone Number: 314-123-4567
License Plate#: mrg-143
State of license plate: MO
Make of vehicle: Toyota Camry
Color of vehicle: Blue
Primary Mode of Transportation to Campus: Metro bus and MetroLink
Secondary Mode of Transportation (if applicable):
(Walk, Bike, Carpool/Vanpool, Metro Bus/Shuttle, MetroLink,:
Motorcycle/Scooter, Off-Site Parking Permit, or specify other):
Employees and Campus Residents Only:
Campus Box Number: '4321'
Campus Phone Extension: 5-1234
#!/usr/bin/env ruby
require 'yaml'
def process(block)
data = {}
block.each do |line|
key, value = line.split(/:/)
data[key.strip] = value.nil? ? nil : value.strip
end
puts data.to_yaml
end
in_block = false
in_html = false
block = []
ARGF.each_line do |line|
next if in_html
line.gsub!(/[>*]/, '') # remove all >'s and *'S from lines
line = line.strip
next if line =~ /^$/ # skip empty lines
block << line if in_block
if line =~ /^\d+-\d+ Occasional Parking Program - Renewal/
in_block = true
end
if line =~ /^Campus Phone/
in_block = false
process(block)
block = []
end
if line =~ /Content-Type: text\/html/
in_html = true
end
if line =~ /Content-Type: text\/plain/
in_html = false
end
end
Delivered-To: dgtized@gmail.com
Received: by 10.114.174.176 with SMTP id bt16csp27306ldc;
Fri, 14 Jun 2013 07:27:02 -0700 (PDT)
Return-Path: <aheaslet@gmail.com>
Received-SPF: pass (google.com: domain of aheaslet@gmail.com designates 10.180.107.104 as permitted sender) client-ip=10.180.107.104
Authentication-Results: mr.google.com;
spf=pass (google.com: domain of aheaslet@gmail.com designates 10.180.107.104 as permitted sender) smtp.mail=aheaslet@gmail.com;
dkim=pass header.i=@gmail.com
X-Received: from mr.google.com ([10.180.107.104])
by 10.180.107.104 with SMTP id hb8mr623945wib.26.1371220021895 (num_hops = 1);
Fri, 14 Jun 2013 07:27:01 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:date:message-id:subject:from:to:content-type;
bh=ebUv82176H4UWIHjfo9MZSrO44ztCGSEUxV1eIdhiOs=;
b=qjSZ6tlTaY+JpNpCmpFKOXhF1ZvJVOSnkZRr+JqdyLboYRwsBRVn8BvpOP9NVkW6pL
1LTofppDA6InntsxgzKdeYnFaE8LG+gBjpR/vIlfdf0JkgLpjXjwwfrXM0I+Rdn/8+Lh
6EIKyG9vn67rQ8sBN/VjyBsKruu1UO0UUk9We0/oW+dB96Q7ANhJJrMVVsjQb8voWF3N
+u3XI2i0HAWjZpcO+m92zCXdpgEGUjD6l9gApEUH4PZb+5lKiNROUmi3iiBDbE44duN5
XxS7rQ6WHR52/nmA8cAi/nrebeKUBmVzq3Wj7eiEaBxY/leQaPkW0KJUpAZCui3Ep9TU
E0Jw==
MIME-Version: 1.0
X-Received: by 10.180.107.104 with SMTP id hb8mr623945wib.26.1371220021885;
Fri, 14 Jun 2013 07:27:01 -0700 (PDT)
Received: by 10.194.3.105 with HTTP; Fri, 14 Jun 2013 07:27:01 -0700 (PDT)
Date: Fri, 14 Jun 2013 09:27:01 -0500
Message-ID: <CAFLr0A4h_9F4pC0Bk30k0aYeuQwWv+eNfkhabymCWJjjTu5Ltg@mail.gmail.com>
Subject: Data sets
From: Andy Heaslet <aheaslet@gmail.com>
To: Charles Comstock <dgtized@gmail.com>
Content-Type: multipart/alternative; boundary=e89a8f234ce5504b6d04df1e0a8a
--e89a8f234ce5504b6d04df1e0a8a
Content-Type: text/plain; charset=ISO-8859-1
So there are about three versions with a handful of exceptions:
The first example below has the carrots next to a lot of text, I also get
lots of responses just like that but without the carrots, and then the 2nd
example below is the basic info and format that's in the majority of these
emails.
Any help is grrrrreatly appreciated! Thanks!
Andy
------------------------------------------------------------------------
> 2013-2014 Occasional Parking Program Members:
>
> My name is Andy Heaslet and I am the new Alternative Transportation
> Coordinator for the Danforth Campus. Among my various responsibilities
> is administering the Occasional Parking Program. I wanted take this
> time to introduce myself as your new contact for this program and to
> thank you for being a member. I look forward to assisting you this
> year with your alternative transportation needs!
>
> As you may know, the end of the fiscal year is quickly approaching,
> which means that it's time to consider your options for next year's
> commute! We are pleased that the Occasional Parking Program will be
> continuing for 2013-2014, and that there will be no price increase for
> the discounted daily permits. Those who enroll in the program will
> still be entitled to discounted daily permits for the cost of $2.50
> each. At this time, the number of dailies offered during the year
> will remain the same: full-time students and employees will be limited
> to a total of 48 discounted dailies in the fiscal year, and part-time
> students and employees will be limited to a total of 24 discounted
> dailies. Daily permits sold through the Occasional Parking Program
> will still be available only in increments of eight, and will be
> available for purchase only at the office of Parking & Transportation
Services on the North Campus.
>
> A representative from Parking Services will be on hand at this year's
> U-Pass Distribution Center to sell Occasional Parking permits. The
> U-Pass Distribution Center will be held in the Danforth University
> Center Visitor's Lounge on Monday, June 17, 2013 and Tuesday, June 18,
> 2013 and is scheduled to be open from 11 am - 2 pm. Occasional Parking
> permits will be payable by cash or check only.
>
> To simplify the renewal process for current Occasional Parking Program
> members, we are offering program renewal by e-mail. Since copies of
> vehicle registrations and driver's licenses are currently on file for
> all existing members, we will simply need members who wish to continue
> participating in this program to complete the renewal form that is
> included in this message. Please reply to this message with the
> required information, or cut and paste the information below into a
> new message and send it to
> parktrans@wustl.edu<mailto:parktrans@wustl.edu>. Once we have
> received your completed form, we will send you a new Occasional Parking
Membership Card, which you may begin using on July 1, 2013.
>
> We will be staying in contact with 2013-2014 Occasional Parking
> Program members via e-mail, keeping everyone informed of new features
> and Distribution Center dates, so please make sure that you send the
> completed form from the e-mail address at which you would like to
> receive all future communication for the program. If you wish to
> receive Occasional Parking Program information at a different e-mail
> address, please include it on the form that you send to Parking Services.
>
> We look forward to continuing to serve you, and hope for your
> continued cooperation in making the program a great success!
>
> Best regards,
> Andy Heaslet
> Alternative Transportation Coordinator Washington University Parking &
> Transportation Services
> 314-935-9275
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> * *
> * * * * * * * *
>
> 2012-2013 Occasional Parking Program - Renewal
>
> Name:Richard Ruland
> Employee
> Part-Time Status
> Employee ID Number: 040807
> Home Address: 505 Westgate
> City: U City
> State: MO
> Zip Code: 63130
> Home/Mobile Phone Number: 727-2137
> License Plate#: PB9 A8S
> State of license plate: MO
> Make of vehicle: Nissan
> Color of vehicle: slate blue
>
>
> Primary Mode of Transportation to Campus: walk Secondary Mode of
> Transportation (if applicable):
> (Walk, Bike, Carpool/Vanpool, Metro Bus/Shuttle, MetroLink,
> Motorcycle/Scooter, Off-Site Parking Permit, or specify other)
>
> Employees and Campus Residents Only:
> * Campus Box Number: 1122
> * Campus Phone Extension: 4408
>
-----------------------------------------------------------------
*2013-2014 Occasional Parking Program - Renewal* *
Name: Jane Doe
Student or Employee: Employee
Full-Time or Part-Time Status: full time
Employee/Student ID Number: 012365*
*Home Address: 710 westgate
*
*City: St Louis
*
*State: MO*
*Zip Code: 63130*
*Home/Mobile Phone Number: 314-123-4567*
*License Plate#: mrg-143 *
*State of license plate: MO*
*Make of vehicle: Toyota Camry*
*Color of vehicle: Blue*
*
Primary Mode of Transportation to Campus:* Metro bus and MetroLink*
Secondary Mode of Transportation (if applicable):* *
(Walk, Bike, Carpool/Vanpool, Metro Bus/Shuttle, MetroLink,
Motorcycle/Scooter, Off-Site Parking Permit, or specify other)* *
Employees and Campus Residents Only**:* *
* Campus Box Number:* 4321*
* Campus Phone Extension:* 5-1234
--e89a8f234ce5504b6d04df1e0a8a
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">
<p class=3D""></p><p class=3D"">
</p><p class=3D"">So there are about three versions with a handful of excep=
tions:</p><p class=3D"">The first example below has the carrots next to a l=
ot of text, I also get lots of responses just like that but without the car=
rots, and then the 2nd example below is the basic info and format that&#39;=
s in the majority of these emails.</p>
<p class=3D"">Any help is grrrrreatly appreciated!=A0 Thanks!<br></p><p cla=
ss=3D"">Andy<br></p><p class=3D"">-----------------------------------------=
-------------------------------<br></p><p class=3D"">&gt; 2013-2014 Occasio=
nal Parking Program Members:</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; My name is Andy Heaslet and I am the new Alternative
Transportation </p>
<p class=3D"">&gt; Coordinator for the Danforth Campus. Among my
various responsibilities </p>
<p class=3D"">&gt; is administering the Occasional Parking Program. I
wanted take this </p>
<p class=3D"">&gt; time to introduce myself as your new contact for
this program and to </p>
<p class=3D"">&gt; thank you for being a member. I look forward to
assisting you this </p>
<p class=3D"">&gt; year with your alternative transportation needs!</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; As you may know, the end of the fiscal year is
quickly approaching, </p>
<p class=3D"">&gt; which means that it&#39;s time to consider your options
for next year&#39;s </p>
<p class=3D"">&gt; commute!<span style>=A0 </span>We
are pleased that the Occasional Parking Program will be </p>
<p class=3D"">&gt; continuing for 2013-2014, and that there will be no
price increase for </p>
<p class=3D"">&gt; the discounted daily permits.<span style>=A0 </span>Thos=
e who enroll in the program will </p>
<p class=3D"">&gt; still be entitled to discounted daily permits for
the cost of $2.50 </p>
<p class=3D"">&gt; each.<span style>=A0 </span>At this
time, the number of dailies offered during the year </p>
<p class=3D"">&gt; will remain the same: full-time students and
employees will be limited </p>
<p class=3D"">&gt; to a total of 48 discounted dailies in the fiscal
year, and part-time </p>
<p class=3D"">&gt; students and employees will be limited to a total of
24 discounted </p>
<p class=3D"">&gt; dailies.<span style>=A0
</span>Daily permits sold through the Occasional Parking Program </p>
<p class=3D"">&gt; will still be available only in increments of eight,
and will be </p>
<p class=3D"">&gt; available for purchase only at the office of Parking
&amp; Transportation Services on the North Campus.</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; A representative from Parking Services will be on
hand at this year&#39;s </p>
<p class=3D"">&gt; U-Pass Distribution Center to sell Occasional
Parking permits.<span style>=A0 </span>The </p>
<p class=3D"">&gt; U-Pass Distribution Center will be held in the
Danforth University </p>
<p class=3D"">&gt; Center Visitor&#39;s Lounge on Monday, June 17, 2013 and
Tuesday, June 18,</p>
<p class=3D"">&gt; 2013 and is scheduled to be open from 11 am - 2 pm.
Occasional Parking </p>
<p class=3D"">&gt; permits will be payable by cash or check only.</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; To simplify the renewal process for current
Occasional Parking Program </p>
<p class=3D"">&gt; members, we are offering program renewal by
e-mail.<span style>=A0 </span>Since copies of </p>
<p class=3D"">&gt; vehicle registrations and driver&#39;s licenses are
currently on file for </p>
<p class=3D"">&gt; all existing members, we will simply need members
who wish to continue </p>
<p class=3D"">&gt; participating in this program to complete the
renewal form that is </p>
<p class=3D"">&gt; included in this message.<span style>=A0 </span>Please r=
eply to this message with the </p>
<p class=3D"">&gt; required information, or cut and paste the
information below into a </p>
<p class=3D"">&gt; new message and send it to </p>
<p class=3D"">&gt; <a href=3D"mailto:parktrans@wustl.edu%3cmailto:parktrans=
@wustl.edu">parktrans@wustl.edu&lt;mailto:parktrans@wustl.edu</a>&gt;.<span=
style>=A0 </span>Once we have </p>
<p class=3D"">&gt; received your completed form, we will send you a new
Occasional Parking Membership Card, which you may begin using on July 1, 20=
13.</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; We will be staying in contact with 2013-2014
Occasional Parking </p>
<p class=3D"">&gt; Program members via e-mail, keeping everyone
informed of new features </p>
<p class=3D"">&gt; and Distribution Center dates, so please make sure
that you send the </p>
<p class=3D"">&gt; completed form from the e-mail address at which you
would like to </p>
<p class=3D"">&gt; receive all future communication for the
program.<span style>=A0 </span>If you wish to </p>
<p class=3D"">&gt; receive Occasional Parking Program information at a
different e-mail </p>
<p class=3D"">&gt; address, please include it on the form that you send
to Parking Services.</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; We look forward to continuing to serve you, and hope
for your </p>
<p class=3D"">&gt; continued cooperation in making the program a great
success!</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; Best regards,</p>
<p class=3D"">&gt; Andy Heaslet</p>
<p class=3D"">&gt; Alternative Transportation Coordinator Washington
University Parking &amp; </p>
<p class=3D"">&gt; Transportation Services</p>
<p class=3D"">&gt; 314-935-9275</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * *</p>
<p class=3D"">&gt; * *</p>
<p class=3D"">&gt; * * * * * * * *</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; 2012-2013 Occasional Parking Program - Renewal</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; Name:Richard Ruland</p>
<p class=3D"">&gt;<span style>=A0 </span>Employee</p>
<p class=3D"">&gt; Part-Time Status</p>
<p class=3D"">&gt; Employee ID Number: 040807</p>
<p class=3D"">&gt; Home Address: 505 Westgate</p>
<p class=3D"">&gt; City: U City</p>
<p class=3D"">&gt; State: MO</p>
<p class=3D"">&gt; Zip Code: 63130</p>
<p class=3D"">&gt; Home/Mobile Phone Number: 727-2137</p>
<p class=3D"">&gt; License Plate#: PB9 A8S</p>
<p class=3D"">&gt; State of license plate: MO</p>
<p class=3D"">&gt; Make of vehicle: Nissan</p>
<p class=3D"">&gt; Color of vehicle: slate blue</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; Primary Mode of Transportation to Campus: walk Secondary
Mode of </p>
<p class=3D"">&gt; Transportation (if applicable):</p>
<p class=3D"">&gt; (Walk, Bike, Carpool/Vanpool, Metro Bus/Shuttle,
MetroLink, </p>
<p class=3D"">&gt; Motorcycle/Scooter, Off-Site Parking Permit, or
specify other)</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">&gt; Employees and Campus Residents Only:</p>
<p class=3D"">&gt; * Campus Box Number: 1122</p>
<p class=3D"">&gt; * Campus Phone Extension: 4408</p>
<p class=3D"">&gt;=A0</p>
<p class=3D"">=A0</p>
<p></p><p class=3D"">------------------------------------------------------=
----------- <br></p>
<p class=3D""><b><u><span style=3D"font-family:&quot;Garamond&quot;,&quot;s=
erif&quot;">2013-2014
Occasional Parking Program - Renewal</span></u></b> <b><span style=3D"font-=
family:&quot;Garamond&quot;,&quot;serif&quot;"><br>
<br>
Name: =A0=A0Jane Doe<br>
Student or Employee: Employee<br>
Full-Time or Part-Time Status: =A0full time<br>
Employee/Student ID Number: 012365</span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;">Home
Address: 710 westgate<br></span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;">City: St Louis<br></span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;">State: MO</span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;">Zip Code:
63130</span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;">Home/Mobile
Phone Number: 314-123-4567</span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;">License
Plate#:=A0 mrg-143 =A0=A0=A0=A0=A0=A0=A0 </span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;">State of
license plate: MO</span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;">Make of
vehicle: Toyota Camry</span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;">Color of
vehicle: Blue</span></b></p>
<p class=3D""><b><span style=3D"font-family:&quot;Garamond&quot;,&quot;seri=
f&quot;"><br>
<br>
Primary Mode of Transportation to Campus:</span></b> Metro bus and MetroLin=
k<b><span style=3D"font-family:&quot;Garamond&quot;,&quot;serif&quot;"><br>
Secondary Mode of Transportation (if applicable):</span></b> <b><i><span st=
yle=3D"font-family:&quot;Garamond&quot;,&quot;serif&quot;"><br>
(Walk, Bike, Carpool/Vanpool, Metro Bus/Shuttle, MetroLink, <br>
Motorcycle/Scooter, Off-Site Parking Permit, or specify other)</span></i></=
b> <b><i><u><span style=3D"font-family:&quot;Garamond&quot;,&quot;serif&quo=
t;"><br>
<br>
Employees and Campus Residents Only</span></u></i></b><b><i><span style=3D"=
font-family:&quot;Garamond&quot;,&quot;serif&quot;">:</span></i></b> <b><sp=
an style=3D"font-family:&quot;Garamond&quot;,&quot;serif&quot;"><br>
* Campus Box Number:</span></b> 4321<b><span style=3D"font-family:&quot;Gar=
amond&quot;,&quot;serif&quot;"><br>
* Campus Phone Extension:</span></b> 5-1234</p>
</div>
--e89a8f234ce5504b6d04df1e0a8a--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment