ft_42 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ft_42 +37 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b97751e8896fa2ede78cbd7dd940a0e447170ad2
|
4
|
+
data.tar.gz: 353737f501a46b2c39e42b4c05026d8c91c16152
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb8fb4d2e2e5511a10a270ba6dee26337be42dfc4cc7c1465af4fac562584cd34f00095adc63ecff31d117e98211a7adf90a661b7c29f22977d072309d16d397
|
7
|
+
data.tar.gz: 68d26cf4a6e66c426d0be019149835fb1f03a91d72ffda8374a52bbfb0e83eff1c3566dcb7179acf30b69e58b3116800ddb1d78142adbf81f3d45438fc2f7fcb
|
data/bin/ft_42
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
2
|
require "active_support/all"
|
4
3
|
require "action_view"
|
5
4
|
require "pastel"
|
@@ -7,10 +6,20 @@ require "oauth2"
|
|
7
6
|
require "ruby-progressbar"
|
8
7
|
|
9
8
|
HOURS_NEEDED = 38
|
10
|
-
USERNAME = ARGV[0]
|
9
|
+
USERNAME = ARGV[0]
|
11
10
|
UID = ENV.fetch("FT42_UID")
|
12
11
|
SECRET = ENV.fetch("FT42_SECRET")
|
13
12
|
|
13
|
+
def cluster(host)
|
14
|
+
case true
|
15
|
+
when host.include?("z1") then "Cluster 1"
|
16
|
+
when host.include?("z2") then "Cluster 2"
|
17
|
+
when host.include?("z3") then "Cluster 3"
|
18
|
+
when host.include?("z3") then "Cluster 4"
|
19
|
+
else host
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
14
23
|
# get token
|
15
24
|
client = OAuth2::Client.new(UID, SECRET, site: "https://api.intra.42.fr")
|
16
25
|
token = client.client_credentials.get_token
|
@@ -22,7 +31,7 @@ right_now = Time.current.to_s.split(" ")[0...-1].join("T")
|
|
22
31
|
# Make requests
|
23
32
|
user = token.get("/v2/users/#{USERNAME}", params: { per_page: 100 }).parsed
|
24
33
|
sessions = token.get("/v2/users/#{USERNAME}/locations?range[begin_at]=#{time_ago},#{right_now}", params: { per_page: 100 }).parsed
|
25
|
-
phone = %x(
|
34
|
+
phone = %x(ldapsearch -Q uid=#{USERNAME} | grep mobile).split.last
|
26
35
|
|
27
36
|
# calculate hours
|
28
37
|
duration = 0
|
@@ -35,17 +44,38 @@ hours = (duration / 60 / 60).round
|
|
35
44
|
|
36
45
|
# currently working on
|
37
46
|
in_progress = user["projects_users"].select { |project| project["status"] == "in_progress" }.map { |in_prog| in_prog["project"]["name"] }
|
47
|
+
in_progress = ["something, maybe.."] if in_progress.empty?
|
38
48
|
|
39
49
|
# printer
|
40
50
|
pastel = Pastel.new
|
41
|
-
|
51
|
+
|
52
|
+
puts pastel.bright_green.bold("#{user['first_name']} #{user['last_name']}")
|
53
|
+
|
54
|
+
# is active?
|
55
|
+
active = false
|
56
|
+
sessions.each do |session|
|
57
|
+
if session["begin_at"].to_time - session["end_at"].to_time == -600.0
|
58
|
+
puts "Is #{pastel.bright_green.bold('active')} at " + pastel.bright_green.bold("#{cluster(session['host'])}") + "."
|
59
|
+
if active
|
60
|
+
puts pastel.red.bold("Warning: Logged in on more than one computer. Please logout from #{session['host']} ASAP.")
|
61
|
+
end
|
62
|
+
active = true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
unless active
|
67
|
+
puts "Was last active " + pastel.bright_green.bold("#{ActionView::Base.new.time_ago_in_words(sessions.first['end_at'].to_time)} ago") + " at #{pastel.bright_green.bold(cluster(sessions.first['host']))}."
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "Has " + pastel.bright_green.bold("#{hours} #{hours == 1 ? 'hour' : 'hours'}") + " in the clusters this week, starting #{Time.current.beginning_of_week.strftime("%A, %B #{Time.current.beginning_of_week.day.ordinalize}")}. #{'Go to sleep.' if hours > 60}"
|
42
71
|
|
43
72
|
percent_complete = ((hours.to_f / HOURS_NEEDED.to_f) * 100).round
|
44
73
|
if (percent_complete <= 100)
|
45
|
-
|
46
|
-
|
47
|
-
|
74
|
+
progressbar_needed = ProgressBar.create(progress_mark: "█", length: 60, format: "%t: |" + pastel.red("%B") + "| #{hours}/38 hours")
|
75
|
+
percent_complete.times { progressbar_needed.increment }
|
76
|
+
puts progressbar_needed
|
48
77
|
end
|
49
78
|
|
50
79
|
puts "Currently working on #{pastel.bright_green.bold(in_progress.to_sentence)}."
|
51
80
|
puts "You may contact #{user['first_name'].titleize} at #{pastel.bright_green.bold(ActiveSupport::NumberHelper.number_to_phone(phone))}."
|
81
|
+
puts "Currently level: #{pastel.bright_green.bold(ActiveSupport::NumberHelper.number_to_rounded(user['cursus_users'].select { |cursus| cursus['cursus']['name'] == "42" }.first['level'], precision: 2))}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ft_42
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matias Fernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|