Last active
August 29, 2015 14:12
-
-
Save HenningBrandt/5d68466176df4a5b71f2 to your computer and use it in GitHub Desktop.
Simple script to scrape for one line ASCII-Art and filter them by character-type and length. It than constructs a shell-script array and ouputs it to the file argument.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Simple script to scrape for one line ASCII-Art and filter them by character-type and length. | |
# It than constructs a shell-script array and ouputs it to the file argument. | |
# | |
# Author: Henning Brandt | |
# Created: 04.01.15 | |
# Licence: MIT | |
# | |
require "nokogiri" | |
require "open-uri" | |
file_path = ARGV[0] | |
if file_path.nil? abort("Filepath argument missing!") | |
URL = "http://1lineart.kulaone.com/home?page=" | |
ascii_art = [] | |
(0..12).each do |i| | |
doc = Nokogiri::HTML(open(URL + i.to_s)) | |
doc.css(".views-field-field-art-line-value").each do |elem| | |
ascii_art << elem.content.strip | |
end | |
end | |
file = File.new(file_path, "w") | |
# Some ASCIIs on the site are only names of people and such, so I reject all that only consists of alphanumericals | |
# Because I use the strings as part of my custom zsh prompt, I reject all strings greater than ten characters. | |
ascii_art.reject! { |elem| elem.length > 10 || elem =~ /^[A-Za-z0-9]*$/ }.each_with_index do |ascii, index| | |
# escape single quotes, because I want to use the output in a shell script | |
ascii = ascii.gsub(/'/){ %q(\047) } | |
# Construct shell array | |
file.puts("ascii[#{(index + 1).to_s}]='" + ascii + "';\n") | |
end | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment