distraction 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/bin/distraction +31 -29
- data/lib/distraction.rb +107 -107
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MjVlNjczOTc2OTZmZjBiYWY5MjBmODlmOTJhZmJmZjMwOTBmZWU2MQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4651bc861438ecc5f2c05b9b8b6efed46be8a49d
|
4
|
+
data.tar.gz: 0fa69d8ca9551366735c4a9d824bcd0e19e0ad0e
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MjQ3YTFjYzAxY2E5NTU5NWYzZDgyN2M1ZmIwNzdlNDY1ZTMzMzI1NzdlYzg3
|
11
|
-
ZGZlMDYwMGVhMGNkYmNhZTBkMjY1NDM5YWMxOGEyNjkwN2MxYzU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NGEwODc2Y2MwMzdiODY3OTQ3Mjg2ZGU2OWJjOTY0ZWRhYzQzODgxODY4ZDJh
|
14
|
-
MjgzYjc2MmUzZmI2NTU2M2RhNzZhZmE3MGY0ZmI0OTA5N2U1YjM4ZTI4Yjhm
|
15
|
-
OGMxY2RkOTU4MWEzM2NkOGQyOWI2MjM4ODQwNWEyNzUzOWQ3YjM=
|
6
|
+
metadata.gz: dc4b13cb6b79e5be6b80a4798767f41b9485d20ef14b854d1f13b3df34a3d7cd9bba0f8ace311757bcfe68502b1ce8d70a56236a3f9c8f5ad2b555d06c853ccf
|
7
|
+
data.tar.gz: 463299f0ea7288df57939e044407be2eadce07448cc840e4e2d90474b624de7487aee48876bfaad9d1e3ada2756fb8fa826a66f6f75489dc43973a5b2068b468
|
data/bin/distraction
CHANGED
@@ -3,37 +3,39 @@
|
|
3
3
|
require 'distraction'
|
4
4
|
require 'rubygems'
|
5
5
|
|
6
|
+
VERSION = "0.0.3"
|
7
|
+
|
6
8
|
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
# get arguments
|
10
|
+
args = ARGV.join(" ")
|
11
|
+
abort(VERSION) if args == "--version" || args == "-v"
|
10
12
|
|
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
|
-
|
13
|
+
case args
|
14
|
+
when /^reddit/
|
15
|
+
args = args.split(" ")
|
16
|
+
if args[1]
|
17
|
+
Distraction.reddit_top(args[1])
|
18
|
+
else
|
19
|
+
Distraction.reddit_top("all")
|
20
|
+
end
|
21
|
+
when "fact"
|
22
|
+
Distraction.reddit_fact(false)
|
23
|
+
when "fact open"
|
24
|
+
Distraction.reddit_fact(true)
|
25
|
+
when /^vid/
|
26
|
+
Distraction.reddit_vid()
|
27
|
+
when "hn"
|
28
|
+
Distraction.hn()
|
29
|
+
else
|
30
|
+
puts "I can't do that! But I can do the following:\n\n"\
|
31
|
+
" distraction reddit Displays the top ten posts on the Reddit homepage\n"\
|
32
|
+
" distraction reddit [subreddit] Displays the top ten posts in [subreddit]\n"\
|
33
|
+
" distraction fact Displays an interesting fact\n"\
|
34
|
+
" distraction fact open Displays a fact and opens up a URL with more information\n"\
|
35
|
+
" distraction vid Displays a random video\n"\
|
36
|
+
" distraction hn Displays the top ten posts on Hacker News"\
|
37
|
+
end
|
36
38
|
|
37
39
|
rescue Interrupt => e # handle CTRL + C cleanly
|
38
|
-
|
40
|
+
puts ""
|
39
41
|
end
|
data/lib/distraction.rb
CHANGED
@@ -2,120 +2,120 @@ require 'net/http'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
class Distraction
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
# display the top link from TIL
|
6
|
+
def self.reddit_fact(open)
|
7
|
+
begin
|
8
|
+
ping = Net::HTTP.get(URI('http://www.reddit.com/r/todayilearned/top.json?t=day&limit=5'))
|
9
|
+
listing = JSON.parse(ping)
|
10
|
+
listing = listing['data']['children']
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
# check if NSFW
|
13
|
+
result = listing.each do |l|
|
14
|
+
break l['data'] if (!l['data']['over_18'])
|
15
|
+
end
|
16
|
+
result_title = result['title'].gsub('TIL', 'Did you know...')
|
17
|
+
result_domain = result['domain']
|
18
|
+
result_url = result['url']
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
case open
|
21
|
+
when true
|
22
|
+
puts result_title + "\n\nOpening link from (#{result_domain}) in 10 seconds... CTRL + C to quit."
|
23
|
+
sleep(10)
|
24
|
+
`open #{result_url}`
|
25
|
+
when false
|
26
|
+
puts result_title + "\n\nYou can type 'distraction fact open' to open the link in a browser."
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
rescue
|
30
|
+
puts "Reddit isn't responding right now. Let's try again later."
|
31
|
+
end
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
# display the top ten links on Reddit frontpage
|
35
|
+
def self.reddit_top(subreddit)
|
36
|
+
begin
|
37
|
+
ping = Net::HTTP.get(URI('http://www.reddit.com/r/' + subreddit + '.json?limit=10'))
|
38
|
+
listing = JSON.parse(ping)
|
39
|
+
listing = listing['data']['children']
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
listing.each_with_index do |l, i|
|
42
|
+
line = " " + (i+1).to_s.rjust(2, " ") + ". " + l['data']['title'] + " (" + l['data']['domain'] + ")"
|
43
|
+
if l['data']['over_18']
|
44
|
+
line = line + " (NSFW)"
|
45
|
+
end
|
46
|
+
puts line
|
47
|
+
end
|
48
|
+
puts "\nWhich link would you like to open?"
|
49
|
+
story = STDIN.gets.chomp()
|
50
|
+
story = story.to_i
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
if ((story < 11) && (story > 0))
|
53
|
+
result = listing[story-1]['data']
|
54
|
+
result_domain = result['domain']
|
55
|
+
result_url = result['url']
|
56
|
+
puts "\nOpening link from (#{result_domain}) in 5 seconds... CTRL + C to quit."
|
57
|
+
sleep(5)
|
58
|
+
`open #{result_url}`
|
59
|
+
else
|
60
|
+
puts "Come on, son."
|
61
|
+
end
|
62
|
+
rescue
|
63
|
+
puts "Oops, either Reddit isn't responding or that subreddit doesn't exist!"
|
64
|
+
end
|
65
|
+
end
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
67
|
+
# picks a random video off r/videos
|
68
|
+
def self.reddit_vid()
|
69
|
+
begin
|
70
|
+
ping = Net::HTTP.get(URI('http://www.reddit.com/r/videos.json')) # gets 25 top vids
|
71
|
+
listing = JSON.parse(ping)
|
72
|
+
listing = listing['data']['children']
|
73
|
+
nsfw_flag = true # true means it is nsfw
|
74
|
+
randomVideo = 0
|
75
|
+
while nsfw_flag
|
76
|
+
randomVideo = rand(24) # random between 0 and 24
|
77
|
+
nsfw_flag = listing[randomVideo]['data']['over_18']
|
78
|
+
end
|
79
|
+
result = listing[randomVideo]['data']
|
80
|
+
result_domain = result['domain']
|
81
|
+
result_url = result['url']
|
82
|
+
puts "Opening video from (#{result_domain}) in 5 seconds... CTRL + C to quit."
|
83
|
+
sleep(5)
|
84
|
+
`open #{result_url}`
|
85
|
+
rescue
|
86
|
+
puts "Oops, something went wrong! Let's try again later."
|
87
|
+
end
|
88
|
+
end
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
90
|
+
# display the top ten links on HN homepage
|
91
|
+
def self.hn()
|
92
|
+
begin
|
93
|
+
ping = Net::HTTP.get(URI('http://hn.algolia.com/api/v1/search?tags=front_page'))
|
94
|
+
listing = JSON.parse(ping)
|
95
|
+
listing = listing['hits']
|
96
|
+
i = 1
|
97
|
+
while (i < 11)
|
98
|
+
line = " " + i.to_s.rjust(2, " ") + ". " + listing[i]['title']
|
99
|
+
i += 1
|
100
|
+
puts line
|
101
|
+
end
|
102
|
+
puts "\nWhich article would you like to open?"
|
103
|
+
story = STDIN.gets.chomp()
|
104
|
+
story = story.to_i
|
105
105
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
106
|
+
if ((story < 11) && (story > 0))
|
107
|
+
result_url = listing[story]['url']
|
108
|
+
if result_url.start_with?("/comments/")
|
109
|
+
result_url = "http://news.ycombinator.com/item?id=#{listing[story]['id']}"
|
110
|
+
end
|
111
|
+
puts "\nOpening link (#{result_url}) in 5 seconds... CTRL + C to quit."
|
112
|
+
sleep(5)
|
113
|
+
`open #{result_url}`
|
114
|
+
else
|
115
|
+
puts "Come on, son."
|
116
|
+
end
|
117
|
+
rescue
|
118
|
+
puts "The HN API we're using isn't responding right now. Let's try again later."
|
119
|
+
end
|
120
|
+
end
|
121
121
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: distraction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Wu
|
@@ -19,7 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- bin/distraction
|
21
21
|
- lib/distraction.rb
|
22
|
-
homepage:
|
22
|
+
homepage: https://github.com/frankjwu/distraction
|
23
23
|
licenses:
|
24
24
|
- MIT
|
25
25
|
metadata: {}
|
@@ -29,17 +29,17 @@ require_paths:
|
|
29
29
|
- lib
|
30
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
41
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.
|
42
|
+
rubygems_version: 2.4.8
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
45
|
summary: A quick distraction in your command line for when you're way too deep in
|