master
E. Almqvist 3 years ago
parent 83611981ca
commit 9ff2fa177c
  1. 4
      wesweb01/evil_infosite/app.rb
  2. 23
      wesweb01/evil_infosite/db_parse.rb
  3. 23
      wesweb01/evil_infosite/views/person.slim

@ -5,8 +5,8 @@ require "slim"
load "db_parse.rb"
person_register = get_db() # get all the parsed data
db_cache = get_db() # get all the parsed data
get "/" do
slim(:person, locals: {persondata: person_register})
slim(:person, locals: {persondata: db_cache})
end

@ -2,14 +2,27 @@
DATA_FILE_PATH = "data/evil_data.csv"
CSV_REGEX = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/
def get_db
person_register = []
person_strings = File.readlines(DATA_FILE_PATH).map do |str|
str.chomp.split(",")[1..-1]
# Go through each line in the .csv file
person_strings = File.readlines(DATA_FILE_PATH).map do |person|
# Use magic regex to parse the csv, this has to be done becuase
# the .csv contains values with commas in them.
# [1..-1] because first element is the index which I can
# get from the .each method (it is not needed, therefore I remove it)
person.chomp.scan(CSV_REGEX)[1..-1].map do |arr|
# String.scan will return an array with each match
# inside it. Remove all nil (those groups did not match)
arr = arr.reject do |elem| elem == nil end
# Take the best first value, this should probably be
# improved. Magic word: TODO: improve this
arr[0]
end
end
# [1..-1] because first element is the index which I can get from the .each method (it
# is not needed, therefore I remove it)
person_strings.each do |person|
person_register << {
@ -22,7 +35,7 @@ def get_db
avatar_url: person[6], # Avatar image URL
freq: person[7], # Frequency (visiting)
role: person[8], # Role (job title/academic)
gender: person[9] # Gender
gender: person[9]# Gender
}
end

@ -4,4 +4,25 @@
.info
h1 #{data[:fname]} #{data[:lname]}
label IPv4 Address: #{data[:ipv4]}
ul
li
label Email:
a href="mailto:#{data[:email]}" = data[:email]
li
label Age:
span #{data[:age]}
li
label IPv4 Address:
a href="https://api.iplocation.net/?ip=#{data[:ipv4]}" target="_blank" = data[:ipv4]
li
label Movie title:
a href="https://www.imdb.com/find?q=#{data[:movie_title]}" target="_blank" = data[:movie_title]
li
label Role:
span #{data[:role]}
li
label Visiting Frequency:
span #{data[:freq]}
li
label Gender:
span #{data[:gender]}

Loading…
Cancel
Save