Skip to content

Instantly share code, notes, and snippets.

@starkcoffee
Created February 9, 2011 06:23
Show Gist options
  • Save starkcoffee/818018 to your computer and use it in GitHub Desktop.
Save starkcoffee/818018 to your computer and use it in GitHub Desktop.
A script to analyse your vodafone bill (if you download the bill as csv)
if ARGV.length != 1
p "Provide a vodafone csv file you donkey!"
exit 666
end
file = open(ARGV[0], 'r').read
# isolate the csv part of the vodafone data file... multiline regex match FTW!!!
BEGIN_MARKER="Call details for.*?\n"
END_MARKER=",,,,,"
regex = /#{BEGIN_MARKER}(.*?)#{END_MARKER}/m
csv_lines = regex.match(file)[1].lines.to_a
records = csv_lines.map {|line| line.chop!.split ','}
headers = records.shift
# turn each array of comma separated values into a hash using the headers. weeeee!!!
records.map! do |record|
record_hash = {}
headers.zip(record) { |heading, value| record_hash[heading]=value }
record_hash
end
# analyse away!!
call_charge_total = records.inject(0) { |sum, record| sum += record["Call Charge"].to_f }
p call_charge_total
# the bill is correct. :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment