-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-foto-index
More file actions
executable file
·42 lines (35 loc) · 879 Bytes
/
create-foto-index
File metadata and controls
executable file
·42 lines (35 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env ruby
require 'erb'
links = {}
home = ENV['HOME']
Dir["#{home}/pictures/2*.jpg"].each do |f|
bn = File.basename(f)
# time_stamp = /(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})/.match(bn)
cmd = "identify -format \"%[EXIF:DateTime]\" #{f}"
exif_timestamp = %x[ #{cmd} ]
/(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2})/.match(exif_timestamp)
tm = Time.new($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, 0)
links[bn] = "<a href='#{bn}'>#{tm.localtime.strftime('%d.%m.%y %H:%M')}</a>"
end
keys = links.keys.sort.reverse
File.open("#{home}/pictures/index.html", "w") { |index|
index.write(ERB.new(<<INDEX).result(binding))
<!DOCTYPE html>
<html>
<head>
<title>Latest pictures</title>
</head>
<body>
<h1>Latest Pictures</h1>
(created <%=Time.now%>)
<ul>
<% keys.each do |k| %>
<li><%=links[k] %>
<% end %>
</ul>
<hr />
<a href="/">Home</a>
</body>
</html>
INDEX
}