mechmarket 0.0.1 → 0.0.2
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/.gitignore +1 -2
- data/Gemfile.lock +8 -8
- data/bin/mechmarket-run +25 -20
- data/bin/mechmarket-test +3 -2
- data/lib/mechmarket/config.rb +7 -4
- data/lib/mechmarket/database.rb +1 -1
- data/mechmarket.gemspec +2 -2
- metadata +1 -2
- data/config-example.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6b7cd4cec8f72d7ce374b635adf2448032a76e328a8e801e104f255c21acab0
|
4
|
+
data.tar.gz: 73698bb7f99b07ef56a16247ea1f6f7997b695254352d0a775d0315cb27b5836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01eea8bcae8009be52bc4f7638d076f182c265726b860a772aba294fa04324ac85e98247f74f32a918370b0da9dd293b70ddb8f0353a57e61f5c02fbb263dd15
|
7
|
+
data.tar.gz: 0f09122ae0466f96159cd68917495bb704f4e7ec663dc21ab414f0cb7e1662a0bf7dc126ea44e2e7c1be757c8c95afdfc646b728978e6207831c9227b2f7c3f2
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mechmarket (0.0.
|
5
|
-
httparty (~> 0.17
|
6
|
-
mail (~> 2.7
|
7
|
-
sqlite3 (~> 1.4
|
4
|
+
mechmarket (0.0.2)
|
5
|
+
httparty (~> 0.17)
|
6
|
+
mail (~> 2.7)
|
7
|
+
sqlite3 (~> 1.4)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -66,11 +66,11 @@ PLATFORMS
|
|
66
66
|
ruby
|
67
67
|
|
68
68
|
DEPENDENCIES
|
69
|
-
awesome_print
|
69
|
+
awesome_print (~> 1.8)
|
70
70
|
mechmarket!
|
71
|
-
rspec
|
72
|
-
rubocop
|
73
|
-
webmock
|
71
|
+
rspec (~> 3.8)
|
72
|
+
rubocop (~> 0.74)
|
73
|
+
webmock (~> 3.7)
|
74
74
|
|
75
75
|
BUNDLED WITH
|
76
76
|
1.16.6
|
data/bin/mechmarket-run
CHANGED
@@ -4,28 +4,33 @@
|
|
4
4
|
require 'bundler/setup'
|
5
5
|
require 'mechmarket'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
begin
|
8
|
+
config = Mechmarket::Config.new
|
9
|
+
mechmarket = Mechmarket::Client.new
|
10
|
+
posts = mechmarket.posts
|
11
|
+
max_id = Mechmarket::Post.max_id
|
11
12
|
|
12
|
-
posts.each do |post|
|
13
|
-
|
14
|
-
end
|
13
|
+
posts.each do |post|
|
14
|
+
post.save if post.new_record?
|
15
|
+
end
|
15
16
|
|
16
|
-
config.queries.each do |query|
|
17
|
-
|
18
|
-
|
17
|
+
config.queries.each do |query|
|
18
|
+
hits = Mechmarket::Post.search(query: query, type: 'Selling', min_id: max_id)
|
19
|
+
next if hits.empty?
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
21
|
+
subject = "Potential r/mechmarket match for \"#{query}\""
|
22
|
+
body = hits.map { |post| "#{post.age}m ago\n#{post.title}\n#{post.url}" }.join("\n\n")
|
23
|
+
Mechmarket::Alert.deliver(config: config, subject: subject, body: body)
|
24
|
+
end
|
24
25
|
|
25
|
-
if posts.empty?
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
|
30
|
-
|
26
|
+
if posts.empty?
|
27
|
+
puts 'API call failed. Check error logs.'
|
28
|
+
exit(1)
|
29
|
+
else
|
30
|
+
puts "[#{Time.now}] Scanned #{posts.size} post(s) for #{config.queries.size} phrases(s)."
|
31
|
+
exit(0)
|
32
|
+
end
|
33
|
+
rescue SQLite3::SQLException => e
|
34
|
+
puts 'Run mechmarket-migrate to create your database.'
|
35
|
+
raise e
|
31
36
|
end
|
data/bin/mechmarket-test
CHANGED
@@ -7,6 +7,7 @@ require 'mechmarket'
|
|
7
7
|
begin
|
8
8
|
puts "max_id: #{Mechmarket::Post.max_id}"
|
9
9
|
puts "m65-a search: #{Mechmarket::Post.search(query: 'm65-a').map(&:title).inspect}"
|
10
|
-
rescue SQLite3::
|
11
|
-
puts '
|
10
|
+
rescue SQLite3::SQLException => e
|
11
|
+
puts 'Run mechmarket-migrate to create your database.'
|
12
|
+
raise e
|
12
13
|
end
|
data/lib/mechmarket/config.rb
CHANGED
@@ -5,10 +5,13 @@ module Mechmarket
|
|
5
5
|
attr_reader :username, :password, :queries
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
config
|
9
|
-
@username
|
10
|
-
@password
|
11
|
-
@queries
|
8
|
+
config = YAML.load_file("#{ENV['HOME']}/.mechmarket/mechmarket.yml")
|
9
|
+
@username = config['username']
|
10
|
+
@password = config['password']
|
11
|
+
@queries = config['queries']
|
12
|
+
rescue Errno::ENOENT => e
|
13
|
+
puts 'Add your username, password and queries to $HOME/.mechmarket/mechmarket.yml.'
|
14
|
+
raise e
|
12
15
|
end
|
13
16
|
end
|
14
17
|
end
|
data/lib/mechmarket/database.rb
CHANGED
@@ -15,7 +15,7 @@ module Mechmarket
|
|
15
15
|
|
16
16
|
class << self
|
17
17
|
def database
|
18
|
-
@database ||= SQLite3::Database.new(
|
18
|
+
@database ||= SQLite3::Database.new("#{ENV['HOME']}/.mechmarket/mechmarket.db")
|
19
19
|
end
|
20
20
|
|
21
21
|
def migrate(debug: false)
|
data/mechmarket.gemspec
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
# To publish the next version:
|
4
4
|
# gem build mechmarket.gemspec
|
5
|
-
# gem push mechmarket-0.0.
|
5
|
+
# gem push mechmarket-0.0.2.gem
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'mechmarket'
|
8
|
-
s.version = '0.0.
|
8
|
+
s.version = '0.0.2'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.licenses = ['MIT']
|
11
11
|
s.authors = ['Chris Estreich']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mechmarket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Estreich
|
@@ -129,7 +129,6 @@ files:
|
|
129
129
|
- bin/mechmarket-migrate
|
130
130
|
- bin/mechmarket-run
|
131
131
|
- bin/mechmarket-test
|
132
|
-
- config-example.yml
|
133
132
|
- lib/mechmarket.rb
|
134
133
|
- lib/mechmarket/alert.rb
|
135
134
|
- lib/mechmarket/client.rb
|