-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo_a_bunch_of_shirts.rb
43 lines (38 loc) · 1.1 KB
/
do_a_bunch_of_shirts.rb
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
42
43
require 'grape'
require 'stringio'
require_relative './render'
require 'faraday'
require 'faraday/multipart'
def bucky(data, filename)
$buckyconn ||= Faraday.new('https://bucky.hackclub.com') do |f|
f.request :multipart
f.request :url_encoded
f.adapter :net_http
end
payload = { file: Faraday::UploadIO.new(StringIO.new(data), 'image/png', filename) }
$buckyconn.post { |req| req.body = payload }.body
end
@shirted_people = []
def shirt_a_person(person)
shirts = generate_shirts(person)
person['shirt_design'] = nil
unless shirts.blank?
person['shirt_design'] = shirts.map.with_index do |shirt, i|
{ url: bucky(shirt, "#{person.id}_#{i}.png") }
end
end
person['action_generate_shirt_design'] = nil
@shirted_people << person
end
ppl = Person.where('action_generate_shirt_design', max_records: 100)
puts "#{ppl.length}"
ppl.each_slice(10) do |people|
@shirted_people = []
begin
people.each { |person| shirt_a_person(person) }
rescue Interrupt, Norairrecord::Error
Person.batch_save(@shirted_people)
end
puts "saving"
Person.batch_save(@shirted_people)
end