lurkmore 0.1.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/bin/lurkmore +5 -0
- data/lib/lurkmore.rb +60 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 353e09098f50b2d49949ed25faa6515b1af3a4f8
|
4
|
+
data.tar.gz: 0f99fd3a7647f27d32c85740c801ef43cb877440
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 310e9b0ec6a1548c46ce2fc624cad60aed842340ff88b462d403f1f2a215f527ab8371468e779594553f6e58bf454c1dba6794b64bcb8f0d7de2b1a2beed216d
|
7
|
+
data.tar.gz: 7592d209ac3b5460989e0b83b0fb6ae67c7ca1f8844d93bf164d1cd8df631bb2e482e8141b3b066fa2c703d147a09e9e686f159677d198403005e8cbebcbcb0b
|
data/bin/lurkmore
ADDED
data/lib/lurkmore.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'tty-spinner'
|
4
|
+
require 'capybara/poltergeist'
|
5
|
+
|
6
|
+
class Lurkmore
|
7
|
+
LINK_RANDOM = 'http://lurkmore.to/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:Random'
|
8
|
+
TERM_WIDTH = Integer(`tput cols`)
|
9
|
+
|
10
|
+
RED = "\e[31m"
|
11
|
+
GREEN = "\e[32m"
|
12
|
+
RESET_COLOR = "\e[0m"
|
13
|
+
|
14
|
+
def self.random
|
15
|
+
spinner = TTY::Spinner.new
|
16
|
+
spinner.run do
|
17
|
+
@session = Capybara::Session.new(:poltergeist)
|
18
|
+
@session.visit(LINK_RANDOM)
|
19
|
+
end
|
20
|
+
begin
|
21
|
+
if $stdout.tty?
|
22
|
+
puts heading(colorcode(@session.first('.firstHeading').text.strip, GREEN))
|
23
|
+
else
|
24
|
+
puts heading(@session.first('.firstHeading').text.strip)
|
25
|
+
end
|
26
|
+
puts
|
27
|
+
puts hr
|
28
|
+
paragraphs = all_p
|
29
|
+
paragraphs.each do |p|
|
30
|
+
text = p.text.strip
|
31
|
+
next if text.empty? || (text.split(' ').size < 10)
|
32
|
+
puts wrap(text), hr
|
33
|
+
end
|
34
|
+
rescue Errno::EPIPE
|
35
|
+
exit(74)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.wrap(s, width=TERM_WIDTH)
|
40
|
+
s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n")
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.all_p
|
44
|
+
@session.all(:css, '.mw-content-ltr p')
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.hr
|
48
|
+
"-" * TERM_WIDTH
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.heading(head_text)
|
52
|
+
half = ( TERM_WIDTH - Integer(head_text.size) ) / 2
|
53
|
+
"-" * half + head_text + "-" * half
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.colorcode(string, code)
|
57
|
+
code + string + RESET_COLOR
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lurkmore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Filonenko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Prints random articles from http://lurkmore.to
|
14
|
+
email: filalex77@gmail.com
|
15
|
+
executables:
|
16
|
+
- lurkmore
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/lurkmore
|
21
|
+
- lib/lurkmore.rb
|
22
|
+
homepage: http://rubygems.org/gems/lurkmore
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.6.7
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Lurkmore:Random
|
46
|
+
test_files: []
|