dtcterm 0.2.1 → 0.3.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 +4 -4
- data/lib/dtcterm.rb +156 -128
- 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: d842481e6c506a5203953357616a94012c6b21b2
|
|
4
|
+
data.tar.gz: c76ce49a90611925641bf9515e33e123952032f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93ae2dd1e594fa7621c1264115759a3e003f51b36b7703a12e828d0db855e201fe588069434a8330be3a6be6518dbc5e9364206889f45a98a01ec12a6ee0117f
|
|
7
|
+
data.tar.gz: 3812a0e252d61ab02e2342070b9006a1dac0222ec6592c8b1381115f8568be4e101b7bc6d17515efa1e1f3ed832a697ee227224472bca129e583d9bc340face6
|
data/lib/dtcterm.rb
CHANGED
|
@@ -1,175 +1,203 @@
|
|
|
1
1
|
module Dtcterm
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
begin
|
|
3
|
+
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
|
|
4
|
+
rescue LoadError
|
|
5
|
+
raise 'win32console is needed to use color on Windows. Try `gem install win32console`'
|
|
6
|
+
end
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
require 'htmlentities'
|
|
9
|
+
require 'optparse'
|
|
10
|
+
require 'open-uri'
|
|
11
|
+
require 'nokogiri'
|
|
12
|
+
require 'rubygems'
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
class << self
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
$using_color = true
|
|
18
|
+
$dtc_choice = ""
|
|
19
|
+
$page = 1
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
BASE_QUOTE_LINK = "http://danstonchat.com/id.html"
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
DTC_FLOP_URL = "http://danstonchat.com/flop50.html"
|
|
24
|
+
DTC_CHRONOLOGICAL_ORDER = "http://danstonchat.com/browse.html"
|
|
25
|
+
DTC_LATEST_URL = "http://danstonchat.com/latest.html"
|
|
26
|
+
DTC_RANDOM_URL = "http://danstonchat.com/random.html"
|
|
27
|
+
DTC_RANDOM_POSITIVE_URL = "http://danstonchat.com/random0.html"
|
|
28
|
+
DTC_TOP_URL = "http://danstonchat.com/top50.html"
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
def version
|
|
31
|
+
'0.3.0'
|
|
32
|
+
end
|
|
31
33
|
|
|
32
34
|
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
class Quote
|
|
37
|
+
attr_accessor :id
|
|
38
|
+
attr_accessor :link
|
|
39
|
+
attr_accessor :quote
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
def initialize
|
|
42
|
+
@id = 0
|
|
43
|
+
@link = ""
|
|
44
|
+
@quote = Array.new { Array.new(2) }
|
|
45
|
+
end
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
def colorize(text)
|
|
48
|
+
"\e[32m#{text}\e[0m"
|
|
49
|
+
end
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
end
|
|
51
|
+
def display
|
|
52
|
+
print "Quote ##{id}\n"
|
|
53
|
+
print "Link: #{link}\n"
|
|
54
|
+
@quote.each do |item|
|
|
55
|
+
print "#{$using_color ? colorize(item[0]) : item[0]} #{item[1]}\n"
|
|
56
56
|
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
57
59
|
|
|
58
60
|
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def get_quote_list(html)
|
|
70
|
-
quote_list = Array.new
|
|
71
|
-
|
|
72
|
-
html.css('div.item-listing').css('div.item').each do |item|
|
|
73
|
-
quote = Quote.new
|
|
74
|
-
quote.id = item["class"].gsub(/[^\d]/, '')
|
|
75
|
-
quote.link = BASE_QUOTE_LINK.gsub("id", quote.id)
|
|
62
|
+
def get_page_html(url)
|
|
63
|
+
begin
|
|
64
|
+
Nokogiri::HTML(open(url))
|
|
65
|
+
rescue
|
|
66
|
+
puts "Can't reach the server."
|
|
67
|
+
exit 1
|
|
68
|
+
end
|
|
69
|
+
end
|
|
76
70
|
|
|
77
|
-
|
|
71
|
+
def get_quote_list(html)
|
|
72
|
+
quote_list = Array.new
|
|
78
73
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
end
|
|
74
|
+
html.css('div.item-listing').css('div.item').each do |item|
|
|
75
|
+
quote = Quote.new
|
|
76
|
+
quote.id = item["class"].gsub(/[^\d]/, '')
|
|
77
|
+
quote.link = BASE_QUOTE_LINK.gsub("id", quote.id)
|
|
84
78
|
|
|
85
|
-
|
|
86
|
-
str = HTMLEntities.new.decode quote_item.content.gsub(/\|newline\|/, "\n")
|
|
79
|
+
quote_item = item.children()[0].children()[0]
|
|
87
80
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
end
|
|
81
|
+
quote_item.children().each do |i|
|
|
82
|
+
if i["class"] == "decoration"
|
|
83
|
+
i.content = "|newline|" + i.content + "|decorationclass|"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
94
86
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
quote_item = quote_item.next()
|
|
98
|
-
end
|
|
99
|
-
end
|
|
87
|
+
while quote_item
|
|
88
|
+
str = HTMLEntities.new.decode quote_item.content.gsub(/\|newline\|/, "\n")
|
|
100
89
|
|
|
90
|
+
str.each_line do |line|
|
|
91
|
+
unless line =~ /^[[:space:]]+$/
|
|
92
|
+
first, second = line.split(/\|decorationclass\|/)
|
|
93
|
+
quote.quote << [first.strip(), second ? second.strip() : second]
|
|
101
94
|
end
|
|
95
|
+
end
|
|
102
96
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
quote_list.each do |quote|
|
|
108
|
-
quote.display
|
|
109
|
-
print "\n\n"
|
|
110
|
-
end
|
|
97
|
+
quote_list << quote
|
|
98
|
+
if (quote_item != nil)
|
|
99
|
+
quote_item = quote_item.next()
|
|
100
|
+
end
|
|
111
101
|
end
|
|
112
102
|
|
|
103
|
+
end
|
|
113
104
|
|
|
105
|
+
quote_list
|
|
106
|
+
end
|
|
114
107
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
end
|
|
108
|
+
def display_quote_list(quote_list)
|
|
109
|
+
quote_list.each do |quote|
|
|
110
|
+
quote.display
|
|
111
|
+
print "\n\n"
|
|
112
|
+
end
|
|
113
|
+
end
|
|
122
114
|
|
|
123
|
-
OptionParser.new do |opts|
|
|
124
115
|
|
|
125
|
-
opts.banner = "Usage: dtcterm one_quote_option [color_option]"
|
|
126
116
|
|
|
127
|
-
|
|
117
|
+
def main(options)
|
|
118
|
+
def self.quote_already_set
|
|
119
|
+
unless $dtc_choice.empty?
|
|
120
|
+
puts("Un choix de quote a déjà été fait.")
|
|
121
|
+
exit 1
|
|
122
|
+
end
|
|
123
|
+
end
|
|
128
124
|
|
|
129
|
-
|
|
130
|
-
$using_color = false
|
|
131
|
-
end
|
|
125
|
+
OptionParser.new do |opts|
|
|
132
126
|
|
|
133
|
-
|
|
134
|
-
quote_already_set
|
|
135
|
-
$dtc_choice = DTC_FLOP_URL
|
|
136
|
-
end
|
|
127
|
+
opts.banner = "Usage: dtcterm one_quote_option [color_option]"
|
|
137
128
|
|
|
138
|
-
|
|
139
|
-
quote_already_set
|
|
140
|
-
$dtc_choice = DTC_LATEST_URL
|
|
141
|
-
end
|
|
129
|
+
opts.version = version
|
|
142
130
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
end
|
|
131
|
+
opts.on("-c", "--no-color", "Enlève la couleur.") do
|
|
132
|
+
$using_color = false
|
|
133
|
+
end
|
|
147
134
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
135
|
+
opts.on("-f", "--flop", "Rubrique `flop50`.") do
|
|
136
|
+
quote_already_set
|
|
137
|
+
$dtc_choice = DTC_FLOP_URL
|
|
138
|
+
end
|
|
152
139
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
140
|
+
opts.on("-l", "--latest", "Rubrique `Derniers ajours`.") do
|
|
141
|
+
quote_already_set
|
|
142
|
+
$dtc_choice = DTC_LATEST_URL
|
|
143
|
+
end
|
|
157
144
|
|
|
158
|
-
|
|
145
|
+
opts.on("-o", "--order", "Rubrique `Ordre chronologique`.") do
|
|
146
|
+
quote_already_set
|
|
147
|
+
$dtc_choice = DTC_CHRONOLOGICAL_ORDER
|
|
148
|
+
end
|
|
159
149
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
150
|
+
opts.on("-p", "--page PAGE", "Page choisie") do |p|
|
|
151
|
+
begin
|
|
152
|
+
$page = Integer(p)
|
|
153
|
+
if $page < 1
|
|
154
|
+
raise ArgumentError
|
|
163
155
|
end
|
|
156
|
+
rescue
|
|
157
|
+
puts("L'argument page n'est pas un entier correct (doit être >= 1).")
|
|
158
|
+
exit 1
|
|
159
|
+
end
|
|
160
|
+
end
|
|
164
161
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
162
|
+
opts.on("-r", "--random", "Rubrique `random`.") do
|
|
163
|
+
quote_already_set
|
|
164
|
+
$dtc_choice = DTC_RANDOM_URL
|
|
165
|
+
end
|
|
169
166
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
opts.on("-R", "--random0", "Rubrique `random > 0`") do
|
|
168
|
+
quote_already_set
|
|
169
|
+
$dtc_choice = DTC_RANDOM_POSITIVE_URL
|
|
173
170
|
end
|
|
171
|
+
|
|
172
|
+
opts.on("-t", "--top", "Rubrique `top50`") do
|
|
173
|
+
quote_already_set
|
|
174
|
+
$dtc_choice = DTC_TOP_URL
|
|
175
|
+
end
|
|
176
|
+
end.parse!(options)
|
|
177
|
+
|
|
178
|
+
if $dtc_choice.empty?
|
|
179
|
+
puts("Il faut choisir une rubrique.")
|
|
180
|
+
exit 1
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
unless options.empty?
|
|
184
|
+
puts("Liste d'argument incorrects.")
|
|
185
|
+
exit 1
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
if $page > 1
|
|
189
|
+
if $dtc != DTC_LATEST_URL and $dtc_choice != DTC_CHRONOLOGICAL_ORDER
|
|
190
|
+
puts("Impossible de choisir une page pour cette catégorie.")
|
|
191
|
+
exit 1
|
|
192
|
+
else
|
|
193
|
+
fp = $dtc_choice.split(/\.html/,)
|
|
194
|
+
$dtc_choice = fp[0] + "/" + $page.to_s + ".html"
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
html = get_page_html($dtc_choice)
|
|
199
|
+
quote_list = get_quote_list(html)
|
|
200
|
+
display_quote_list(quote_list)
|
|
174
201
|
end
|
|
202
|
+
end
|
|
175
203
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dtcterm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Loïc Runarvot
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-09-
|
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|