poster 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d47c21464ef3ae3769689c2c423cb249d040a68
4
- data.tar.gz: 6e00845104fa2af0f24b1d793bef8c96546ff34f
3
+ metadata.gz: d05019846d273db23de21ea10fa4c3563e707e66
4
+ data.tar.gz: 4cde6f1fbe4c5282a99f0ad544bd0ec8ca59d6f5
5
5
  SHA512:
6
- metadata.gz: d41102b0a5db14388cda2bb74403c1a71f253026ec576968f67c066bf3f1e71f63f396615c18c43f48f376a47c6140deadff7ae28270bfb876b8e8c6cf340624
7
- data.tar.gz: c8eecc96190b08532a02348294a753aefcbf266adfee1b1f910a28fc6f2a7d0d90ea53d24cccf858b356d0aa1f04bf5af10e69335c5c2d4af1c4fbd8e54da3d6
6
+ metadata.gz: 2be512d044a6b2153372a564026acbcc051f2ed907800f7d04e239a50360a65c4616a68fdfebd73a03eb0fa8427138475800c3c12b59e4147cc8750bd02e188b
7
+ data.tar.gz: ef33b8c8ab2bb7340019df130677135f4db4e8d1b28b94761e18ed953d34f53ad7b9f1b1a87a1c00dace1b5dbb623fcd6106b3a7d65ad898181ac668f2e3754d
data/bin/poster CHANGED
@@ -1,32 +1,89 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Script to execute repetitive tasks
3
3
  lib = File.expand_path('../../lib', __FILE__)
4
+ tmp = File.expand_path('../../tmp', __FILE__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
 
6
7
  require 'bundler/setup'
7
8
  require 'poster'
8
9
 
9
- # Accessing Bitcointalk: just to test that Faraday works properly
10
-
11
10
  require 'uri'
12
11
  require 'faraday'
12
+ require 'faraday-cookie_jar'
13
13
  require 'nokogiri'
14
14
  require "pp"
15
15
 
16
16
  # Establish Faraday connection
17
- def connect uri
17
+ def connect uri, encoding: :url_encoded
18
18
  Faraday.new(:url => "#{uri.scheme}://#{uri.host}") do |faraday|
19
+ faraday.request :multipart
20
+ faraday.request :url_encoded
21
+ # faraday.use FaradayMiddleware::FollowRedirects, limit: 3
22
+ faraday.use :cookie_jar
19
23
  faraday.response :logger # log requests to STDOUT
20
24
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
21
25
  end
22
26
  end
23
27
 
24
28
  # Extract contacts from a single page
25
- uri = URI.parse('https://bitcointalk.org/index.php?topic=145506.46400')
29
+ # uri = URI.parse('https://bitcointalk.org/index.php?topic=145506.46400')
30
+ # conn = connect(uri)
31
+ # response = conn.get "#{uri.path}?#{uri.query}"
32
+ # doc = Nokogiri::HTML(response.body)
33
+ # posts = doc.xpath("//div[@class='post']").map {|p| p.children.reduce('') {|m,e| m + ' ' + e.content}}
34
+ # pp posts, posts.size
35
+ # users = doc.xpath("//tr/td/b/a").map {|p| p.children.first.content}
36
+ # pp users, users.size
37
+
38
+ user, pass = *ARGV
39
+
40
+ # Decorator for HTML pages
41
+ class Nokogiri::HTML::Document
42
+ # <span style="font-size: 130%;" id="hellomember"> Hello <b>Arvicco</b></span>
43
+ def logged?
44
+ !self.xpath("//span[@id='hellomember']").empty?
45
+ end
46
+
47
+ def input_field name
48
+ unless self.xpath("//input[@name='#{name}']").empty?
49
+ self.xpath("//input[@name='#{name}']").first['value']
50
+ end
51
+ end
52
+ end
53
+
54
+ # Login
55
+ uri = URI.parse('https://bitcointalk.org/index.php?action=login2')
26
56
  conn = connect(uri)
27
- response = conn.get "#{uri.path}?#{uri.query}"
28
- doc = Nokogiri::HTML(response.body)
29
- posts = doc.xpath("//div[@class='post']").map {|p| p.children.reduce('') {|m,e| m + ' ' + e.content}}
30
- pp posts, posts.size
31
- users = doc.xpath("//tr/td/b/a").map {|p| p.children.first.content}
32
- pp users, users.size
57
+ response = conn.post do |req|
58
+ req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
59
+ req.url "#{uri.path}?#{uri.query}"
60
+ req. body = {user: user, passwrd: pass}
61
+ end
62
+ p response.status
63
+ p response.body
64
+
65
+ # Check board posting page first (to get sequence numbers)
66
+ response = conn.get "/index.php?action=post;board=92.0"
67
+
68
+ p response.status
69
+ post_page = Nokogiri::HTML(response.body)
70
+ puts "Logged #{post_page.logged?}"
71
+ # p post_page.xpath("//form[@name='postmodify']//input").each {|i| puts "#{i['name']}:#{i['value']}," }
72
+ seqnum = post_page.input_field('seqnum')
73
+ sc = post_page.input_field('sc')
74
+ p seqnum, sc
75
+
76
+ # Create new post
77
+ response = conn.post do |req|
78
+ req.options.timeout = 5 # open/read timeout in seconds
79
+ req.headers['Content-Type'] = 'multipart/form-data'
80
+ req.url "/index.php?action=post2;start=0;board=92"
81
+ req.body = { topic: 0, subject: "Test номер #{rand(10)}", icon: "xx", message: "Test тестирование",
82
+ notify: 0, do_watch: 0, selfmod: 0, lock: 0, goback: 1, ns: "NS", post: "Post",
83
+ additional_options: 0, sc: sc, seqnum: seqnum }
84
+ end
85
+
86
+ p response.status
87
+ File.open("#{tmp}/response.html", 'w+') {|f| f.write(response.body) }
88
+ new_page = Nokogiri::HTML(response.body)
89
+ puts "Logged #{new_page.logged?}"
@@ -1,3 +1,3 @@
1
1
  module Poster
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency 'nokogiri', '~> 1.5'
24
24
  spec.add_development_dependency 'faraday', '~> 0.8'
25
+ spec.add_development_dependency 'faraday-cookie_jar'
25
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - arvicco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-28 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday-cookie_jar
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Poster is a tool that helps with repetitive tasks (like forum posting)
70
84
  automation.
71
85
  email: