ft_42 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ft_42 +21 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5776c47618b5745702d18a9d9c665d6058a294f7
|
4
|
+
data.tar.gz: 5684793369b572b2915d8f974c6ad1511fb4891d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d2cfaee7e91767588d093a03b840ec45341fe770ffa58038d374241b1aa3c042df6b893bb8208e7df43d05069774513bb9130e366090717cc7832b09d2b40fe
|
7
|
+
data.tar.gz: d041535a5225e12cd1df682bb17b91cc55e1ca5d941f865c237e903d5990b2247df706cd130fdd4e5043940b2e47cf8ddbcce1e7eccb2f5c1d1e4370d3f5b090
|
data/bin/ft_42
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "active_support/all"
|
4
|
+
require "action_view"
|
4
5
|
require "pastel"
|
5
6
|
require "oauth2"
|
6
7
|
require "ruby-progressbar"
|
@@ -10,27 +11,41 @@ USERNAME = ARGV[0];
|
|
10
11
|
UID = ENV.fetch("FT42_UID")
|
11
12
|
SECRET = ENV.fetch("FT42_SECRET")
|
12
13
|
|
14
|
+
# get token
|
13
15
|
client = OAuth2::Client.new(UID, SECRET, site: "https://api.intra.42.fr")
|
14
16
|
token = client.client_credentials.get_token
|
15
17
|
|
18
|
+
# helpers
|
16
19
|
time_ago = Time.current.beginning_of_week.to_s.split(" ")[0...-1].join("T")
|
17
20
|
right_now = Time.current.to_s.split(" ")[0...-1].join("T")
|
18
21
|
|
19
|
-
|
22
|
+
# Make requests
|
23
|
+
user = token.get("/v2/users/#{USERNAME}", params: { per_page: 100 }).parsed
|
24
|
+
sessions = token.get("/v2/users/#{USERNAME}/locations?range[begin_at]=#{time_ago},#{right_now}", params: { per_page: 100 }).parsed
|
25
|
+
phone = %x( ldapsearch -Q uid=#{USERNAME} | grep mobile ).split.last
|
20
26
|
|
27
|
+
# calculate hours
|
21
28
|
duration = 0
|
22
29
|
sessions.each do |session|
|
23
30
|
begin_at = session["begin_at"].to_time
|
24
31
|
end_at = session["end_at"].to_time
|
25
32
|
duration += (end_at - begin_at)
|
26
33
|
end
|
27
|
-
|
28
34
|
hours = (duration / 60 / 60).round
|
29
35
|
|
36
|
+
# currently working on
|
37
|
+
in_progress = user["projects_users"].select { |project| project["status"] == "in_progress" }.map { |in_prog| in_prog["project"]["name"] }
|
38
|
+
|
39
|
+
# printer
|
30
40
|
pastel = Pastel.new
|
31
|
-
puts pastel.bright_green.bold("#{
|
41
|
+
puts pastel.bright_green.bold("#{user['first_name'].titleize} #{user['last_name'].titleize}") + " has " + pastel.bright_green.bold("#{hours} #{hours == 1 ? 'hour' : 'hours'}") + " in the clusters this week."
|
32
42
|
|
33
43
|
percent_complete = ((hours.to_f / HOURS_NEEDED.to_f) * 100).round
|
34
|
-
|
35
|
-
|
36
|
-
|
44
|
+
if (percent_complete <= 100)
|
45
|
+
progressbar_needed = ProgressBar.create(progress_mark: "█", length: 60, format: "%t: |" + pastel.bright_green("%B") + "| #{hours}/38 hours")
|
46
|
+
percent_complete.times { progressbar_needed.increment }
|
47
|
+
puts progressbar_needed
|
48
|
+
end
|
49
|
+
|
50
|
+
puts "Currently working on #{pastel.bright_green.bold(in_progress.to_sentence)}."
|
51
|
+
puts "You may contact #{user['first_name'].titleize} at #{pastel.bright_green.bold(ActiveSupport::NumberHelper.number_to_phone(phone))}."
|