karma_count 0.0.1
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 +7 -0
- data/bin/karma_count +5 -0
- data/lib/cli.rb +156 -0
- data/lib/karma_count.rb +5 -0
- data/lib/scraper.rb +60 -0
- data/lib/student.rb +31 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 473edd137897149168140f2d04e8ac7dd2711bf9
|
4
|
+
data.tar.gz: 1c232275ff1ccc838e207771a229aca7304c8c8c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 782edd81b3053a24309d55f75274276f2bb04928f459bd680984e0825f4c96fb0311e7c00b995d519a2e0d29553680690e6d4cb078c81b64283dd78f1ef2d329
|
7
|
+
data.tar.gz: 1fb5c8031758a67aefaf4db10003702422f89674bc07194f3ff5f714b24de74495ca4791939192d7f6da564121b46ec14c134de8741c2be0b9f9cf0e5ac00824
|
data/bin/karma_count
ADDED
data/lib/cli.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
require_relative "../lib/scraper.rb"
|
2
|
+
require_relative "../lib/student.rb"
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class Cli
|
6
|
+
BASE_URL = "http://students.learn.co"
|
7
|
+
|
8
|
+
def run
|
9
|
+
header
|
10
|
+
accumulate_info_and_explain
|
11
|
+
the_app
|
12
|
+
end
|
13
|
+
|
14
|
+
def accumulate_info_and_explain
|
15
|
+
sleep 1
|
16
|
+
puts "IT MAY TAKE A MINUTE TO LOAD ALL THE USERS"
|
17
|
+
sleep 1
|
18
|
+
puts ""
|
19
|
+
puts "IF YOU'D LIKE TO CONTINUE WORK WHILE YOU WAIT"
|
20
|
+
sleep 1
|
21
|
+
puts ""
|
22
|
+
puts "PLEASE PRESS CMD + T TO OPEN A NEW TAB"
|
23
|
+
make_students
|
24
|
+
sleep 2
|
25
|
+
header
|
26
|
+
puts ""
|
27
|
+
puts "BUT HONESTLY IT WILL TAKE A FEW MINUTES"
|
28
|
+
add_attributes_to_students
|
29
|
+
puts ""
|
30
|
+
puts "WE'RE ALMOST THERE I PROMISE"
|
31
|
+
sleep 5
|
32
|
+
header
|
33
|
+
puts ""
|
34
|
+
puts "OKAY I LIED...IT'LL BE ABOUT 5 MINUTES"
|
35
|
+
add_karma_to_students
|
36
|
+
end
|
37
|
+
|
38
|
+
def header
|
39
|
+
system 'clear'
|
40
|
+
puts "__________________WELCOME TO THE KARMA COUNT_________________________"
|
41
|
+
puts ""
|
42
|
+
end
|
43
|
+
|
44
|
+
def continue_or_quit
|
45
|
+
puts "Press 1 to go back to the main menu, press 2 to exit"
|
46
|
+
next_input = gets.strip
|
47
|
+
if next_input == "1"
|
48
|
+
the_app
|
49
|
+
else
|
50
|
+
puts "Check back later to see if you've advanced!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def the_app
|
55
|
+
|
56
|
+
input = nil
|
57
|
+
|
58
|
+
loop do
|
59
|
+
header
|
60
|
+
puts "1. TOP 10 KARMA CONTENDERS"
|
61
|
+
puts ""
|
62
|
+
puts "2. ALL KARMA CONTENDERS"
|
63
|
+
puts ""
|
64
|
+
puts "3. SEARCH"
|
65
|
+
|
66
|
+
input = gets.strip
|
67
|
+
break if input == "1" || input == "2" || input == "3"
|
68
|
+
end
|
69
|
+
|
70
|
+
if input == "1"
|
71
|
+
top_10_karma
|
72
|
+
elsif input == "2"
|
73
|
+
all_karma
|
74
|
+
else
|
75
|
+
search_for_karma_position
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
def make_students
|
81
|
+
students_array = Scraper.scrape_index_page(BASE_URL)
|
82
|
+
Student.create_from_collection(students_array)
|
83
|
+
end
|
84
|
+
|
85
|
+
def add_attributes_to_students
|
86
|
+
Student.all.each do |student|
|
87
|
+
attributes = Scraper.scrape_profile_page(student.profile_url)
|
88
|
+
student.add_student_attributes(attributes)
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_karma_to_students
|
94
|
+
Student.all.each do |student|
|
95
|
+
attributes = Scraper.scrape_learn_for_karma(student.github_url)
|
96
|
+
student.add_student_attributes(attributes)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def top_10_karma
|
101
|
+
header
|
102
|
+
counter = 0
|
103
|
+
competitors = Student.all.select do |student|
|
104
|
+
student.karma if !(student.karma.nil? )
|
105
|
+
end
|
106
|
+
competitors.sort_by!{|student| student.karma}
|
107
|
+
puts "___________________________KARMA TOP 10______________________________"
|
108
|
+
competitors.reverse.each do |student|
|
109
|
+
counter += 1
|
110
|
+
puts ""
|
111
|
+
puts " #{counter}. #{student.name.upcase} from #{student.location} with #{student.karma} POINTS!"
|
112
|
+
puts "---------------------------------------------------------------------"
|
113
|
+
break if counter == 10
|
114
|
+
end
|
115
|
+
continue_or_quit
|
116
|
+
end
|
117
|
+
|
118
|
+
def all_karma
|
119
|
+
header
|
120
|
+
competitors = Student.all.select do |student|
|
121
|
+
student.karma if !(student.karma.nil? )
|
122
|
+
end
|
123
|
+
competitors.sort_by!{|student| student.karma}
|
124
|
+
puts "_________________________KARMA HIGH SCORE____________________________"
|
125
|
+
competitors.reverse.each_with_index do |student, index|
|
126
|
+
puts ""
|
127
|
+
puts " #{index.to_i.next}. #{student.name.upcase} from #{student.location} with #{student.karma} POINTS!"
|
128
|
+
puts "---------------------------------------------------------------------"
|
129
|
+
end
|
130
|
+
continue_or_quit
|
131
|
+
end
|
132
|
+
|
133
|
+
def search_for_karma_position
|
134
|
+
header
|
135
|
+
competitors = Student.all.select do |student|
|
136
|
+
student.karma if !(student.karma.nil? )
|
137
|
+
end
|
138
|
+
search_name = nil
|
139
|
+
competitors.sort_by!{|student| student.karma}
|
140
|
+
puts "_________________________KARMA SEARCH_______________________________"
|
141
|
+
puts ""
|
142
|
+
puts "Enter your first and last name"
|
143
|
+
sleep 1
|
144
|
+
puts "If no results occur, check your name for spelling or check if there is an issue with your profile on www.students.learn.co"
|
145
|
+
search_name = gets.strip.downcase
|
146
|
+
competitors.reverse.each_with_index do |student,index|
|
147
|
+
if search_name == student.name.downcase
|
148
|
+
header
|
149
|
+
puts ""
|
150
|
+
puts " You are in position #{index.to_i.next}!"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
sleep 1
|
154
|
+
continue_or_quit
|
155
|
+
end
|
156
|
+
end
|
data/lib/karma_count.rb
ADDED
data/lib/scraper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
class Scraper
|
5
|
+
|
6
|
+
def self.scrape_index_page(index_url)
|
7
|
+
student_array = []
|
8
|
+
|
9
|
+
doc = Nokogiri::HTML(open(index_url))
|
10
|
+
|
11
|
+
doc.search(".student-card").collect do |student|
|
12
|
+
{
|
13
|
+
name: student.search("h4.student-name").text,
|
14
|
+
location: student.search("p.student-location").text,
|
15
|
+
profile_url: "http://students.learn.co/#{student.search("a").attribute("href").value}"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.scrape_profile_page(profile_url)
|
21
|
+
specific_student = {}
|
22
|
+
begin
|
23
|
+
doc = Nokogiri::HTML(open(profile_url))
|
24
|
+
rescue
|
25
|
+
specific_student[:github_url] = nil
|
26
|
+
else
|
27
|
+
doc.search(".social-icon-container a").each do |social|
|
28
|
+
if social.attribute("href").value.scan(/github.com/) == ["github.com"]
|
29
|
+
specific_student[:github_url] = social.attribute("href").value
|
30
|
+
else
|
31
|
+
specific_student[:github_url] = nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
specific_student
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def self.scrape_learn_for_karma(github_url)
|
40
|
+
specific_karma = {}
|
41
|
+
if github_url != nil
|
42
|
+
gh_parse = URI::parse(github_url)
|
43
|
+
learn_url = "https://www.learn.co" + gh_parse.path + ".html"
|
44
|
+
begin
|
45
|
+
doc = Nokogiri::HTML(open(learn_url))
|
46
|
+
rescue
|
47
|
+
specific_karma[:karma] = nil
|
48
|
+
else
|
49
|
+
points = doc.css(".karma-points h3").text.to_i
|
50
|
+
specific_karma[:karma] = points
|
51
|
+
end
|
52
|
+
else
|
53
|
+
specific_karma[:karma] = nil
|
54
|
+
end
|
55
|
+
specific_karma
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
end
|
60
|
+
|
data/lib/student.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
class Student
|
3
|
+
attr_accessor :name, :location, :profile_url, :github_url, :karma
|
4
|
+
def name=(name)
|
5
|
+
@name = name
|
6
|
+
end
|
7
|
+
STUDENTS =[]
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
attributes.each do |k, v|
|
11
|
+
self.send(("#{k}="), v)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.create_from_collection(students_array)
|
16
|
+
students_array.each do |student|
|
17
|
+
Student.new(student)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_student_attributes(attributes_hash)
|
22
|
+
attributes_hash.each do |k,v|
|
23
|
+
self.send(("#{k}="), v)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.all
|
28
|
+
STUDENTS
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: karma_count
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- PJ Wickwire
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: pjpeterww@gmail.com
|
15
|
+
executables:
|
16
|
+
- karma_count
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/karma_count
|
21
|
+
- lib/cli.rb
|
22
|
+
- lib/karma_count.rb
|
23
|
+
- lib/scraper.rb
|
24
|
+
- lib/student.rb
|
25
|
+
homepage: http://github.com/pajamaw
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.5.2
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: A gem to list out all the learn-verified students karma points
|
49
|
+
test_files: []
|
50
|
+
has_rdoc:
|