Created
January 20, 2016 21:11
-
-
Save jeremybmerrill/062b388521e9e43b67da to your computer and use it in GitHub Desktop.
quick-and-dirty code things, CSV backend
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
require 'sinatra' | |
require 'csv' | |
$csv_read_path = "my_thing.uncoded.csv" | |
$csv_write_path = "my_thing.coded.csv" | |
$data = CSV.read($csv_read_path, {:headers => true}) | |
def write_csv! | |
CSV.open($csv_write_path, 'wb') do |csv| | |
csv << ["website", "terms_url", "arbitration?", "class_action?", "tos_cnt", "checked?"] | |
$data.each{|row| csv << row} | |
end | |
end | |
go_to_next = lambda do | |
already_coded = $data.select{|row| !row["checked?"].nil? && row["checked?"] == "TRUE" }.map{|row| row["website"] }.uniq | |
# find first uncoded site. | |
$data.each_with_index do |row, index| | |
puts index.inspect | |
if !already_coded.include?(row["website"]) && | |
(!row["terms_url"].nil? || row["arbitration?"] || row["class_action?"]) | |
id = index | |
redirect "/#{id}" | |
end | |
end | |
"nothing here" | |
end | |
get '/', &go_to_next | |
post '/', &go_to_next | |
get '/:id' do | |
row = $data[params[:id].to_i] | |
@site_url = row["site_url"] | |
@terms_url = row["terms_url"] | |
@id = params[:id] | |
@what_to_look_for = [row["arbitration?"], row["class_action?"]].join("|") | |
puts [@site_url, @terms_url, @what_to_look_for].inspect | |
erb :code_tos | |
end | |
post '/:id' do | |
coding = if params[:action] == "yes" | |
true | |
elsif params[:action] == "no" | |
false | |
else | |
nil | |
end | |
row = $data[params[:id].to_i] | |
row["checked?"] = coding | |
puts params.inspect | |
puts row["checked?"].inspect | |
write_csv! | |
redirect "/" | |
end | |
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
<html> | |
<head></head> | |
<body> | |
<h1><%= @site_url %></h1> | |
<h2><a href="<%= @terms_url %>" target="_blank"><%= @terms_url %></a></h2> | |
<h2><%= @what_to_look_for %></h2> | |
<form action="/<%= @id %>" method="post"> | |
<input type="submit" name="action" value="yes" style="background-color: green;" /> | |
<input type="submit" name="action" value="no" style="background-color: red;" /> | |
</form> | |
<iframe src="<%= @terms_url%>" width="100%" height="1000" sandbox="allow-scripts"></iframe> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment