github-trending 0.2.0
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/.gitignore +24 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +76 -0
- data/github-trending.gemspec +36 -0
- data/lib/github-trending.rb +1 -0
- data/lib/github_trending.rb +9 -0
- data/lib/github_trending/project.rb +11 -0
- data/lib/github_trending/scraper.rb +79 -0
- data/lib/github_trending/version.rb +5 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef0aa1b70905ec567a8c807dbef3533aafa0e9c4
|
4
|
+
data.tar.gz: 9cdf036867ab073a8ed6e628e33864618dd173b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 381960564b115fc0f642fc7d8ef5bd6f2d3ab10a99eda17fb9fd67728d82ca7eec148433953cf05c18a442a63824354c98ada1df8a1f439f2cfc072ece4fa5a0
|
7
|
+
data.tar.gz: e5685802bfa029512476061dc695d87161d2561585c471cef9ee7e75cba652ed0fd80061a606986621beeb0c008a27f0d3cc921e87d990af2126a579bb5b36e1
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.DS_Store
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
24
|
+
TODO.txt
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
github-trending
|
2
|
+
===============
|
3
|
+
|
4
|
+
`github-trending` is a gem that fetches [Trending repositories on GitHub](https://github.com/trending). It's functionality was extracted from the command-line utility [`git-trend`](https://github.com/rochefort/git-trend), so almost all of the code is written by **[@rochefort](https://github.com/rochefort)**.
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'github-trending', github: 'sheharyarn/github-trending'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ gem install github-trending
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Require it if you haven't:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'github-trending'
|
33
|
+
```
|
34
|
+
|
35
|
+
Get the day's trending repos:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
repos = Github::Trending.get
|
39
|
+
repos.each do |r|
|
40
|
+
puts "#{r.name} (#{r.star_count} stargazers)"
|
41
|
+
puts "--- #{r.description}\n\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
# =>
|
45
|
+
# sindresorhus/awesome-nodejs (712 stargazers)
|
46
|
+
# --- A curated list of delightful Node.js packages and resources.
|
47
|
+
#
|
48
|
+
# MrSwitch/hello.js (536 stargazers)
|
49
|
+
# --- A Javascript RESTFUL API library for connecting with OAuth2 services, such as Google+ API, Facebook Graph # and Windows Live Connect
|
50
|
+
#
|
51
|
+
# ColdSauce/CosmosBrowserAndroid (391 stargazers)
|
52
|
+
# --- Cosmos Browser allows a person to connect to the internet through the use of SMS. No data or wifi required.
|
53
|
+
#
|
54
|
+
# ...
|
55
|
+
```
|
56
|
+
|
57
|
+
You can also fetch by a specific language:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
ruby_repos = Github::Trending.get 'ruby'
|
61
|
+
```
|
62
|
+
|
63
|
+
To get a list of all languages:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
languages = Github::Trending.all_languages
|
67
|
+
```
|
68
|
+
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
1. Fork it ( https://github.com/sheharyarn/github-trending/fork )
|
73
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
74
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
75
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
76
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'github_trending/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'github-trending'
|
8
|
+
spec.version = Github::Trending::VERSION
|
9
|
+
spec.authors = ['rochefort', 'sheharyarn']
|
10
|
+
spec.email = ['hello@sheharyar.me']
|
11
|
+
spec.summary = 'Fetches Trending Github Repos'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/sheharyarn/github-trending'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.post_install_message = "\n\n Thanks for Installing!\n\n\n"
|
22
|
+
|
23
|
+
spec.add_dependency 'thor', '~> 0.19.1'
|
24
|
+
spec.add_dependency 'mechanize', '~> 2.7.2'
|
25
|
+
spec.add_dependency 'addressable', '~> 2.3.6'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0'
|
31
|
+
spec.add_development_dependency 'rspec-its', '~> 1.0.1'
|
32
|
+
spec.add_development_dependency 'simplecov', '~> 0.9.0'
|
33
|
+
spec.add_development_dependency 'webmock', '~> 1.18.0'
|
34
|
+
|
35
|
+
spec.add_development_dependency 'coveralls'
|
36
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'github_trending'
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'mechanize'
|
3
|
+
require 'addressable/uri'
|
4
|
+
|
5
|
+
module Github
|
6
|
+
module Trending
|
7
|
+
def self.get(language = nil, since = nil)
|
8
|
+
scraper = Github::Trending::Scraper.new
|
9
|
+
scraper.get(language, since)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all_languages
|
13
|
+
scraper = Github::Trending::Scraper.new
|
14
|
+
scraper.list_languages
|
15
|
+
end
|
16
|
+
|
17
|
+
class Scraper
|
18
|
+
BASE_HOST = 'https://github.com'
|
19
|
+
BASE_URL = "#{BASE_HOST}/trending"
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@agent = Mechanize.new
|
23
|
+
@agent.user_agent = "github-trending #{VERSION}"
|
24
|
+
proxy = URI.parse(ENV['http_proxy']) if ENV['http_proxy']
|
25
|
+
@agent.set_proxy(proxy.host, proxy.port, proxy.user, proxy.password) if proxy
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(language = nil, since = nil)
|
29
|
+
projects = []
|
30
|
+
page = @agent.get(generate_url_for_get(language, since))
|
31
|
+
|
32
|
+
page.search('.repo-list-item').each do |content|
|
33
|
+
project = Project.new
|
34
|
+
meta_data = content.search('.repo-list-meta').text
|
35
|
+
project.lang, project.star_count = extract_lang_and_star_from_meta(meta_data)
|
36
|
+
project.name = content.search('.repo-list-name a').text.split.join
|
37
|
+
project.description = content.search('.repo-list-description').text.gsub("\n", '').strip
|
38
|
+
projects << project
|
39
|
+
end
|
40
|
+
fail ScrapeException if projects.empty?
|
41
|
+
projects
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_languages
|
45
|
+
languages = []
|
46
|
+
page = @agent.get(BASE_URL)
|
47
|
+
page.search('div.select-menu-item a').each do |content|
|
48
|
+
href = content.attributes['href'].value
|
49
|
+
# objective-c++ =>
|
50
|
+
language = href.match(/github.com\/trending\?l=(.+)/).to_a[1]
|
51
|
+
languages << CGI.unescape(language) if language
|
52
|
+
end
|
53
|
+
languages
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def generate_url_for_get(language, since)
|
59
|
+
uri = Addressable::URI.parse(BASE_URL)
|
60
|
+
if language || since
|
61
|
+
uri.query_values = { l: language, since: since }.delete_if { |_k, v| v.nil? }
|
62
|
+
end
|
63
|
+
uri.to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
def extract_lang_and_star_from_meta(text)
|
67
|
+
meta_data = text.split('•').map { |x| x.gsub("\n", '').strip }
|
68
|
+
if meta_data.size == 3
|
69
|
+
lang = meta_data[0]
|
70
|
+
star_count = meta_data[1].gsub(',', '').to_i
|
71
|
+
[lang, star_count]
|
72
|
+
else
|
73
|
+
star_count = meta_data[0].gsub(',', '').to_i
|
74
|
+
['', star_count]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github-trending
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rochefort
|
8
|
+
- sheharyarn
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 0.19.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 0.19.1
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: mechanize
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.7.2
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.7.2
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: addressable
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.3.6
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.6
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.6'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.6'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 3.0.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 3.0.0
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rspec-its
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.0.1
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 1.0.1
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: simplecov
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 0.9.0
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 0.9.0
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: webmock
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 1.18.0
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 1.18.0
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: coveralls
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
description: Fetches Trending Github Repos
|
155
|
+
email:
|
156
|
+
- hello@sheharyar.me
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- CHANGELOG.md
|
163
|
+
- Gemfile
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.md
|
166
|
+
- github-trending.gemspec
|
167
|
+
- lib/github-trending.rb
|
168
|
+
- lib/github_trending.rb
|
169
|
+
- lib/github_trending/project.rb
|
170
|
+
- lib/github_trending/scraper.rb
|
171
|
+
- lib/github_trending/version.rb
|
172
|
+
homepage: https://github.com/sheharyarn/github-trending
|
173
|
+
licenses:
|
174
|
+
- MIT
|
175
|
+
metadata: {}
|
176
|
+
post_install_message: |2+
|
177
|
+
|
178
|
+
|
179
|
+
Thanks for Installing!
|
180
|
+
|
181
|
+
|
182
|
+
rdoc_options: []
|
183
|
+
require_paths:
|
184
|
+
- lib
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
requirements: []
|
196
|
+
rubyforge_project:
|
197
|
+
rubygems_version: 2.2.1
|
198
|
+
signing_key:
|
199
|
+
specification_version: 4
|
200
|
+
summary: Fetches Trending Github Repos
|
201
|
+
test_files: []
|