Skip to content

Instantly share code, notes, and snippets.

@iskernel
Last active December 18, 2015 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iskernel/5769759 to your computer and use it in GitHub Desktop.
Save iskernel/5769759 to your computer and use it in GitHub Desktop.
A simple script for extracting the unicodes and the icon names from the Font Awesome cheat-sheet page.
require 'net/http'
#Reads the HTML page
fontAwesomeUri = URI('http://fortawesome.github.io/Font-Awesome/cheatsheet/')
htmlSourceArray = Net::HTTP.get(fontAwesomeUri).split(/\r?\n/)
outputArray = Array.new()
tempString = String.new()
#Extracts the lines containing the unicodes and the icon names
htmlSourceArray.each_with_index do |line,index|
line = line.strip
if(line =~ /<i class="icon-fixed-width">&#x(....)<\/i>/ )
tempString = "0x"+ $1 + " , " + htmlSourceArray[index+1].strip + "\n"
outputArray.push(tempString)
end
end
#Prints to output.txt the results
outputFile = File.open("output.txt","w")
outputArray.each do |line|
outputFile.write(line)
end
puts("Extracted " + outputArray.size().to_s() +
" items from the Font-Awesome cheatsheet. Hurray!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment