wpps 0.2.4 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/pwrslv +81 -49
- data/bin/wp +43 -13
- data/lib/initcommand.rb +63 -0
- data/lib/whiplash/version.rb +1 -1
- data/lib/wputils.rb +29 -3
- metadata +17 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6eee0097df00b23ec18bae46054835c6c86a4ee
|
4
|
+
data.tar.gz: aa53450a075147f36824a65b0a688400376c6c63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10329e5fe521ac3a54ddc0a1c128c4946a4b4d45cbba32bd097c619dd508c894e01cbcebf8109e79927292f3b664cb9f792ba068c3bdfdb2b156d0cd4c075a85
|
7
|
+
data.tar.gz: e298cd434fb30401780d41ef5d064d5919ad93d014dee27f73519d504df61dc69a4294dafcb4874b249d619b9ffea67de4b89fd07a1cf16afa91f169905dfce1
|
data/bin/pwrslv
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
2
3
|
|
3
4
|
require 'rubygems'
|
4
5
|
require 'twitter'
|
@@ -7,12 +8,16 @@ require 'optparse'
|
|
7
8
|
require 'nokogiri'
|
8
9
|
require 'wputils'
|
9
10
|
require 'whiplash/version'
|
11
|
+
require 'initcommand'
|
10
12
|
|
11
|
-
usage = "Usage: pwrslv [
|
13
|
+
usage = "Usage: pwrslv init {url|file} [--ovrwr]\n"\
|
14
|
+
" pwrslv [OPTIONS]"
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
:
|
16
|
+
# Setting default options
|
17
|
+
options = { :maxtweets => 1, # Number of tweets to get from tweeter
|
18
|
+
:interative => false, # No interactive
|
19
|
+
:ovrwr => false, # No overwrite
|
20
|
+
:verbose => 0 # Verbosity level: no message
|
16
21
|
}
|
17
22
|
OptionParser.new do |opt|
|
18
23
|
opt.banner = usage
|
@@ -29,6 +34,9 @@ OptionParser.new do |opt|
|
|
29
34
|
'Maximum number of tweets retrieve from',
|
30
35
|
'a specific TAG'
|
31
36
|
) { |o| options[:maxtweets] = o.to_i }
|
37
|
+
opt.on('--ovrwr',
|
38
|
+
'flag that enables overrides files,',
|
39
|
+
'directories') { |o| options[:ovrwr] = true }
|
32
40
|
opt.on('-t',
|
33
41
|
'--tag TAG',
|
34
42
|
String,
|
@@ -37,7 +45,7 @@ OptionParser.new do |opt|
|
|
37
45
|
) { |o| options[:tag] = o }
|
38
46
|
opt.on('--verbose LEVEL') do |o|
|
39
47
|
options[:verbose] = o.to_i
|
40
|
-
unless 0 <= options[:verbose] and options[:verbose] <=
|
48
|
+
unless 0 <= options[:verbose] and options[:verbose] <= 3
|
41
49
|
puts opt.help
|
42
50
|
exit 1
|
43
51
|
end
|
@@ -52,68 +60,92 @@ OptionParser.new do |opt|
|
|
52
60
|
end
|
53
61
|
end.parse!
|
54
62
|
|
63
|
+
if ARGV[0] == "init" then
|
64
|
+
ARGV.shift
|
65
|
+
if ARGV.length == 1 then
|
66
|
+
createSubTreeDirectory('.powerslave', options[:ovrwr], ARGV[0])
|
67
|
+
exit 0
|
68
|
+
else
|
69
|
+
STDERR.puts usage
|
70
|
+
exit 1
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
55
74
|
unless ARGV.empty? then
|
56
|
-
puts usage
|
75
|
+
STDOUT.puts usage
|
57
76
|
exit 1
|
58
77
|
end
|
59
78
|
|
60
|
-
usertwitter=ARGV[0]
|
79
|
+
# usertwitter=ARGV[0]
|
61
80
|
|
62
81
|
yamlconf = getPScfgFile()
|
63
82
|
client = get_tweeter_client(yamlconf)
|
64
83
|
|
65
84
|
begin
|
66
85
|
tag = getWPTag(options)
|
86
|
+
puts "Tag: #{tag}" if options[:verbose] > 0
|
67
87
|
tweets = client.search(tag)
|
68
|
-
|
88
|
+
puts "Tweets: #{tweets}" if options[:verbose] > 0
|
69
89
|
nro = 0
|
70
90
|
tweets.each do |tw|
|
71
91
|
nro += 1
|
72
|
-
|
92
|
+
printLevelMsg(1, options[:verbose], "Tweet text: #{tw.text}")
|
93
|
+
|
73
94
|
uri = /https:\/\/t.co\/.*/.match(tw.text)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
95
|
+
endIfNil(uri, "Invalid URI on tweet")
|
96
|
+
printLevelMsg(1, options[:verbose], "Getting uri: #{uri[0]} short uri:")
|
97
|
+
|
98
|
+
endIfNil(uri[0], "Invalid URI format")
|
99
|
+
|
100
|
+
ruri = resolve_redirects(uri[0])
|
101
|
+
printLevelMsg(1, options[:verbose], "Resolved URI: #{ruri}")
|
102
|
+
|
103
|
+
idinfo = /http:\/\/pastie\.org\/(\d+)/.match(ruri)
|
104
|
+
printLevelMsg(1, options[:verbose], "Processing idinfo: #{idinfo[0]}")
|
105
|
+
|
106
|
+
endIfNil(idinfo[1], "Invalid Pastie id")
|
107
|
+
printLevelMsg(1, options[:verbose], "Getting Pastie id: #{idinfo[1]}")
|
108
|
+
|
109
|
+
p = Pastie.get(idinfo[1])
|
110
|
+
printLevelMsg(1, options[:verbose], "Pastie: #{p}")
|
111
|
+
endIfNil(p, "get pastie is nil")
|
112
|
+
|
113
|
+
doc = Nokogiri::HTML(p.content)
|
114
|
+
src = doc.at('body').at('pre').
|
115
|
+
inner_html.gsub("<br>", "\n").gsub("<br/>", "\n").
|
116
|
+
gsub("<","<").gsub(">",">").gsub("&", "&").
|
117
|
+
gsub("á", "á").gsub("é", "é").gsub("í", "í").
|
118
|
+
gsub("ó", "ó").gsub("&uactue;", "ú")
|
119
|
+
printLevelMsg(3, options[:verbose], "Source file: #{src}")
|
120
|
+
|
121
|
+
lines = src.split(/\n|\r\n/)
|
122
|
+
lastLine = lines[lines.length - 1]
|
123
|
+
psflnm = /.*filename: (.*)/.match(lastLine)
|
124
|
+
|
125
|
+
endIfNil(psflnm[1], "Cannot get filename from pastie link. Process ends")
|
126
|
+
filename = psflnm[1]
|
127
|
+
|
128
|
+
STDOUT.print "Start writing #{filename}"
|
129
|
+
STDOUT.flush
|
130
|
+
|
131
|
+
begin
|
132
|
+
|
133
|
+
file = File.open(filename, "w+")
|
134
|
+
nwlines = lines.first(lines.length - 1).last(lines.length - 2)
|
135
|
+
file.puts(nwlines)
|
136
|
+
# nwlines.each do |line|
|
137
|
+
# file.puts(line)
|
138
|
+
# end
|
139
|
+
rescue Exception => e
|
140
|
+
STDERR.puts "\nError writting #{filename} due: #{e}"
|
141
|
+
exit 1
|
113
142
|
end
|
143
|
+
|
144
|
+
STDOUT.puts " End writing #{filename}"
|
145
|
+
|
114
146
|
break if nro == options[:maxtweets]
|
115
147
|
end
|
116
148
|
rescue Exception => e
|
117
|
-
puts e
|
149
|
+
STDERR.puts e
|
118
150
|
exit 1
|
119
151
|
end
|
data/bin/wp
CHANGED
@@ -7,15 +7,28 @@ require 'optparse'
|
|
7
7
|
require 'extensions'
|
8
8
|
require 'wputils'
|
9
9
|
require 'whiplash/version'
|
10
|
+
require 'initcommand'
|
10
11
|
|
11
|
-
usage = "Usage: wp [
|
12
|
+
usage = "Usage: wp init {url|file} [--ovrwr]\n"\
|
13
|
+
" wp [options] filename"
|
12
14
|
|
13
|
-
options = {
|
15
|
+
options = { :ovrwr => false,
|
16
|
+
:auth => nil
|
17
|
+
}
|
14
18
|
OptionParser.new do |opt|
|
15
19
|
opt.banner = usage
|
16
20
|
opt.version = Whiplash::VERSION
|
17
21
|
opt.separator ""
|
18
22
|
opt.separator "Specific options:"
|
23
|
+
opt.on('-a',
|
24
|
+
'--auth FILE',
|
25
|
+
String,
|
26
|
+
'A FILE that contains the twitter\'s',
|
27
|
+
'authorizations tokens'
|
28
|
+
) { |o| options[:auth] = o }
|
29
|
+
opt.on('--ovrwr',
|
30
|
+
'flag that enables overrides files,',
|
31
|
+
'directories') { |o| options[:ovrwr] = true }
|
19
32
|
opt.on('-m',
|
20
33
|
'--message MESSAGE',
|
21
34
|
String,
|
@@ -36,6 +49,18 @@ OptionParser.new do |opt|
|
|
36
49
|
end
|
37
50
|
end.parse!
|
38
51
|
|
52
|
+
# Test if is a init command
|
53
|
+
if ARGV[0] == "init" then
|
54
|
+
ARGV.shift
|
55
|
+
if ARGV.length == 1 then
|
56
|
+
createSubTreeDirectory('.whiplash', options[:ovrwr], ARGV[0])
|
57
|
+
exit 0
|
58
|
+
else
|
59
|
+
STDERR.puts usage
|
60
|
+
exit 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
39
64
|
if ARGV.empty? or ARGV.length > 1 then
|
40
65
|
puts usage
|
41
66
|
exit 1
|
@@ -45,22 +70,19 @@ sendfile=ARGV[0]
|
|
45
70
|
unless options[:message] == nil
|
46
71
|
user_message = options[:message]
|
47
72
|
else
|
48
|
-
user_message = ""
|
73
|
+
user_message = "NO MESSAGE"
|
49
74
|
end
|
50
75
|
|
51
|
-
yamlconf = getWPcfgFile()
|
76
|
+
yamlconf = getWPcfgFile(options[:auth])
|
52
77
|
|
53
78
|
# Reading a file
|
54
79
|
unless File::exist? sendfile or File::readable? sendfile
|
55
|
-
puts "Error: file #{sendfile} does not exist or not readable"
|
80
|
+
STDERR.puts "Error: file #{sendfile} does not exist or not readable"
|
56
81
|
exit 1
|
57
82
|
end
|
58
83
|
|
59
84
|
file = File.new(sendfile, "r")
|
60
|
-
conts =
|
61
|
-
file.each_line do |line|
|
62
|
-
conts += line
|
63
|
-
end
|
85
|
+
conts = file.read
|
64
86
|
file.close
|
65
87
|
|
66
88
|
# Create a new paste
|
@@ -69,7 +91,13 @@ lang = le.getLangDesc(File.extname sendfile)
|
|
69
91
|
exts = File.extname sendfile
|
70
92
|
comm = lang.prodComment('filename: ' + (File.basename sendfile))
|
71
93
|
conts = conts + comm
|
72
|
-
p =
|
94
|
+
p = nil
|
95
|
+
begin
|
96
|
+
p = Pastie.create(conts, false, lang.name)
|
97
|
+
rescue => error
|
98
|
+
STDERR.puts "Error pastie: #{error.class} and #{error.message}"
|
99
|
+
exit 1
|
100
|
+
end
|
73
101
|
|
74
102
|
# Getting environment variables that contains the tag info
|
75
103
|
tag = getWPTag(options)
|
@@ -81,12 +109,14 @@ client = get_tweeter_client(yamlconf)
|
|
81
109
|
begin
|
82
110
|
tweet_message = tag + " " + user_message + " " + p.link
|
83
111
|
if tweet_message.length > 240
|
84
|
-
puts "wp cannot send message: #{tweet_message} because too long: #{tweet_emssage.length}"
|
112
|
+
STDERR.puts "wp cannot send message: #{tweet_message} because too long: #{tweet_emssage.length}"
|
85
113
|
exit 1
|
86
114
|
end
|
87
115
|
tweet = client.update(tweet_message)
|
88
|
-
|
116
|
+
histfile = File.join(ENV['HOME'], '.whiplash', 'history', tweet.id.to_s)
|
117
|
+
creatFileWrTr(histfile, conts)
|
118
|
+
STDOUT.puts "Tweet id: #{tweet.id}"
|
89
119
|
rescue Exception => e
|
90
|
-
puts "wp could not
|
120
|
+
STDERR.puts "wp could not send a message due: #{e.message}"
|
91
121
|
exit 1
|
92
122
|
end
|
data/lib/initcommand.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
def createSubTreeDirectory(workDir, ovrwr, url)
|
5
|
+
workPath = ENV['HOME'] + '/' + workDir
|
6
|
+
|
7
|
+
if Dir.exists? workPath then
|
8
|
+
if ovrwr then
|
9
|
+
eraseDirAll(workPath)
|
10
|
+
else
|
11
|
+
STDERR.puts "#{workPath} already exists"
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir.mkdir workPath
|
17
|
+
File.chmod(0700, workPath)
|
18
|
+
Dir.mkdir workPath + '/config'
|
19
|
+
File.chmod(0700, workPath + '/config')
|
20
|
+
Dir.mkdir workPath + '/history'
|
21
|
+
File.chmod(0700, workPath + '/history')
|
22
|
+
createAuthFile(url, workPath + '/config/auth')
|
23
|
+
end
|
24
|
+
|
25
|
+
def eraseDirAll(dir)
|
26
|
+
if Dir.exists? dir then
|
27
|
+
Dir.foreach(dir) do |filename|
|
28
|
+
if not (filename == '.' or filename == '..') then
|
29
|
+
pathname = dir + '/' + filename
|
30
|
+
if File.file? pathname then
|
31
|
+
File.delete pathname
|
32
|
+
elsif File.directory? pathname then
|
33
|
+
eraseDirAll pathname
|
34
|
+
else
|
35
|
+
puts "This never could happen #{pathname}"
|
36
|
+
# Unknown file
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
Dir.delete(dir)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def createAuthFile(url, authfile)
|
45
|
+
uriclass = URI.parse(url)
|
46
|
+
perms = String.new
|
47
|
+
if uriclass.scheme == "http" or uriclass.scheme == "https" then
|
48
|
+
perms = Net::HTTP.get(URI.parse(url))
|
49
|
+
elsif uriclass.scheme == "file" then
|
50
|
+
urlfile = File.open(uriclass.path, "r")
|
51
|
+
perms = urlfile.read
|
52
|
+
urlfile.close
|
53
|
+
else
|
54
|
+
urlfile = File.open(url, "r")
|
55
|
+
perms = urlfile.read
|
56
|
+
urlfile.close
|
57
|
+
end
|
58
|
+
|
59
|
+
# puts perms
|
60
|
+
f = File.new(authfile, File::CREAT|File::TRUNC | File::WRONLY, 0600)
|
61
|
+
f.write perms
|
62
|
+
f.close
|
63
|
+
end
|
data/lib/whiplash/version.rb
CHANGED
data/lib/wputils.rb
CHANGED
@@ -23,13 +23,13 @@ rescue Faraday::Error, Faraday::Error::ConnectionFailed => e
|
|
23
23
|
return nil
|
24
24
|
end
|
25
25
|
|
26
|
-
def getWPcfgFile()
|
27
|
-
filepath=ENV[
|
26
|
+
def getWPcfgFile(file)
|
27
|
+
filepath=file || File.join(ENV['HOME'], '.whiplash', 'config' ,'auth')
|
28
28
|
YAML.load_file(filepath)
|
29
29
|
end
|
30
30
|
|
31
31
|
def getPScfgFile()
|
32
|
-
filepath=ENV[
|
32
|
+
filepath=File.join(ENV['HOME'], '.powerslave', 'config', 'auth')
|
33
33
|
YAML.load_file(filepath)
|
34
34
|
end
|
35
35
|
|
@@ -51,3 +51,29 @@ def getWPTag(options)
|
|
51
51
|
end
|
52
52
|
return ("#" + pTag)
|
53
53
|
end
|
54
|
+
|
55
|
+
def endIfNil(value, msg)
|
56
|
+
if value.nil?
|
57
|
+
STDERR.puts msg
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def printLevelMsg(levelMsg, currentLevel, msg)
|
63
|
+
case currentLevel
|
64
|
+
when 0
|
65
|
+
levelMsg = 0
|
66
|
+
when 1, levelMsg == currentLevel
|
67
|
+
STDERR.puts msg
|
68
|
+
when 2, levelMsg <= currentLevel
|
69
|
+
STDERR.puts msg
|
70
|
+
when 3, levelMsg <= currentLevel
|
71
|
+
STDERR.puts msg
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def creatFileWrTr(filename, msg)
|
76
|
+
hf = File.new(filename, File::CREAT|File::TRUNC|File::RDWR,0600)
|
77
|
+
hf.write msg
|
78
|
+
hf.close
|
79
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wpps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Francisco Cardona McCormick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.
|
19
|
+
version: 5.16.0
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 5.
|
22
|
+
version: 5.16.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 5.
|
29
|
+
version: 5.16.0
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 5.
|
32
|
+
version: 5.16.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: pastie-api
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,20 +56,20 @@ dependencies:
|
|
56
56
|
requirements:
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 0.9.
|
59
|
+
version: 0.9.2
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.9.
|
62
|
+
version: 0.9.2
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.9.
|
69
|
+
version: 0.9.2
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: 0.9.
|
72
|
+
version: 0.9.2
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: faraday_middleware
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,21 +96,21 @@ dependencies:
|
|
96
96
|
requirements:
|
97
97
|
- - "~>"
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: 1.6.
|
99
|
+
version: 1.6.7.2
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 1.6.
|
102
|
+
version: 1.6.7.2
|
103
103
|
type: :runtime
|
104
104
|
prerelease: false
|
105
105
|
version_requirements: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 1.6.
|
109
|
+
version: 1.6.7.2
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version: 1.6.
|
113
|
-
description: Share
|
112
|
+
version: 1.6.7.2
|
113
|
+
description: Share code's snippets by using twitter and pastie
|
114
114
|
email: jfcmacro@gmail.com
|
115
115
|
executables:
|
116
116
|
- wp
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- bin/pwrslv
|
122
122
|
- bin/wp
|
123
123
|
- lib/extensions.rb
|
124
|
+
- lib/initcommand.rb
|
124
125
|
- lib/whiplash/version.rb
|
125
126
|
- lib/wputils.rb
|
126
127
|
homepage: https://github.com/jfcmacro/whiplash
|
@@ -143,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
144
|
version: '0'
|
144
145
|
requirements: []
|
145
146
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.
|
147
|
+
rubygems_version: 2.4.8
|
147
148
|
signing_key:
|
148
149
|
specification_version: 4
|
149
150
|
summary: The whip hand
|