@anonymous/

SweetCommonPress

Ruby

test

fork
loading
Files
  • main.rb
  • candidates-wg-voting-booth
  • data.csv
  • data_id.csv
  • data_id.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6745583110453948","path":"main.rb","file":{"path":"main.rb","content":{"asEncoding":{"base64":"cmVxdWlyZSAnanNvbicKCiRjYW5kaWRhdGVzID0gJXcodHdpbm5lcgllYWdsZXNwaXJpdAllaGlib3NzCWVvbndhcnBlZAlpbmVydGlhCWplZGlnZWlzcwlrb2gJbGVtb3V0aAlsbGZhcm1zCXBnYXJjZ28JcmVkcGFsZXN0aW5vCXJlZ2dhZW11ZmZpbglzaGFkb3dzcHViCXNvcmluLmNyaXN0ZXNjdQlzdGVlbWl0cWEJdHJhdmlzdW5nCW5ubmFydmFlegl0cmFuc2lzdG8JYWlkYXJvamFzd3JpdGVyCXVyYS1zb3VsCWVuZm9yY2VyNDgJYm9iaW5zb24JdGhlY3J5cHRvZHJpdmUJbmVveGlhbikKCgokdm90ZXJzID0ge30KCmRlZiByZWNvcmRfdm90ZShmcm9tLCBpZCwgdG8pCiAgdW5sZXNzICR2b3RlcnMuaGFzX2tleT8oZnJvbSkKICAgICR2b3RlcnNbZnJvbV0gPSBWb3Rlci5uZXcoZnJvbSwgaWQpCiAgZW5kCiAgdm90ZXIgPSAkdm90ZXJzW2Zyb21dCiAgdm90ZXIuYWRkX3ZvdGUodG8pCmVuZAoKZGVmIHJlY29yZF92b3Rlcyhmcm9tLCBkYXRhKQogIGRhdGEuZWFjaCBkbyB8IHZvdGVyIHwKICAgIGlkID0gIiN7dm90ZXJbJ2lkJ119IgogICAgdGFnID0gIiN7dm90ZXJbJ3VzZXJuYW1lJ119IyN7dm90ZXJbJ2Rpc2NyaW1pbmF0b3InXX0iCiAgICByZWNvcmRfdm90ZSh0YWcsIGlkLCBmcm9tKQogIGVuZAplbmQKCmNsYXNzIFZvdGVyCiAgZGVmIGluaXRpYWxpemUodGFnLCBpZCkKICA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HZvdGVycy52YWx1ZXMudG9fanNvbikgfQ=="},"asBuffer":null},"loaded":true}}
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'json'

$candidates = %w(twinner	eaglespirit	ehiboss	eonwarped	inertia	jedigeiss	koh	lemouth	llfarms	pgarcgo	redpalestino	reggaemuffin	shadowspub	sorin.cristescu	steemitqa	travisung	nnnarvaez	transisto	aidarojaswriter	ura-soul	enforcer48	bobinson	thecryptodrive	neoxian)


$voters = {}

def record_vote(from, id, to)
  unless $voters.has_key?(from)
    $voters[from] = Voter.new(from, id)
  end
  voter = $voters[from]
  voter.add_vote(to)
end

def record_votes(from, data)
  data.each do | voter |
    id = "#{voter['id']}"
    tag = "#{voter['username']}##{voter['discriminator']}"
    record_vote(tag, id, from)
  end
end

class Voter
  def initialize(tag, id)
    @tag = tag
    @id = id
    @voted = []
  end

  def voted?(name)
    @voted.include?(name)
  end

  def add_vote(name)
    @voted.push(name)
    @voted.uniq!
  end

  def as_csv
    line = "#{@tag},#{@id},"
    line += $candidates.map do |candidate|
      self.voted?(candidate) ? "1" : "0"
    end.join(',')
  end

  def to_json(stuff)
    {
      tag: @tag,
      id: @id,
      voted: @voted
    }.to_json
  end
end

$candidates.each do |candidate|
  voting_data = JSON.parse(File.read("candidates-wg-voting-booth/#{candidate}.json"))
  record_votes(candidate, voting_data)
end

header = "name,id," + $candidates.join(',')

data = $voters.values.map do |voter|
  voter.as_csv
end.join("\n")

File.open('data_id.csv', 'w') { |file| file.write(header + "\n" + data) }
File.open('data_id.json', 'w') { |file| file.write($voters.values.to_json) }
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]