Botherment. Why make the mods do something that a simple program can do quite easily? My ruby skills are somewhat lacking, so I saw an opportunity to practice them. 30 mins of reading documentation and poking around in the FluxBB code, and ~10 mins of coding produced:
:
require 'mysql'
system "wget
http://www.usps.com/ncsc/lookups/abbr_state.txt"
states = Array.new
abbr = Array.new
states_file = File.open 'abbr_state.txt'
counter = 0
states_file.each_line do |line|
begin
sl = line.split
if sl[2].nil?
unless sl[1].length > 2
states.push sl[0].downcase
abbr.push sl[1].downcase
end
else
if sl[3].nil?
unless sl[2].length > 2
states.push(sl[0].downcase + ' ' + sl[1].downcase)
abbr.push sl[2].downcase
end
else
unless sl[3].length > 2
states.push(sl[0].downcase + ' ' + sl[1].downcase + ' ' + sl[2].downcase)
abbr.push sl[3].downcase
end
end
end
rescue NoMethodError
end
end
states.length.times do |num|
puts "#{states[num]} : #{abbr[num]}"
end
conn = Mysql::new('localhost', 'username', 'password', 'databaseName')
res = conn.query("select username, location from users")
res.each_hash do |user|
old_username = user['username']
if not user['location'].nil?
state_abbr = nil
location = user['location'].downcase
states.length.times do |i|
if location.contains states
state_abbr = abbr
end
end
abbr.length.times do |i|
if location.contains abbr
state_abbr = abbr
end
end
if not state_abbr.nil?
new_username = old_username + state_abbr
cres = conn.query("select id from users where username='#{new_username}'")
conn.query("update users set username='#{new_username}' where username='#{old_username}'") if cres.num_rows == 0
end
end
end
conn.close
system "rm abbr_state.txt"
So many crude hacks! And the mindless code repetition... Isn't it grand?