arbitrage 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/Notes +33 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/arbitrage.gemspec +32 -0
- data/bin/arbitrage +5 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/environment.rb +7 -0
- data/lib/arbitrage.rb +7 -0
- data/lib/arbitrage/Scraper.rb +55 -0
- data/lib/arbitrage/cli.rb +24 -0
- data/lib/arbitrage/input_validator.rb +10 -0
- data/lib/arbitrage/nearby-craigslists.rb +62 -0
- data/lib/arbitrage/product.rb +72 -0
- data/lib/arbitrage/profit.rb +108 -0
- data/lib/arbitrage/version.rb +3 -0
- data/rsc/clzips.csv +32960 -0
- data/rsc/clzips.numbers +0 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec6bae606d5d0d50eaa8f84ceba94798c60be0ef
|
4
|
+
data.tar.gz: d0a2bfcd50030cd77ce26ca86a0cc6aee9eae57d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ccb0d2f44761f075b01033d619aa32a9b5985d8327a1a37680987a638fbd36ee3307551fb84bd7a398a00b0facedcc98740d16b0bec1c687db8d5d856a0e34e
|
7
|
+
data.tar.gz: ccc596646b2696a8e3e0438970b073e4b7cab2f4bba751b44efd2a922a2e41f0331d049a10188bd4765fa212da6a7fb2f59aec19f147ad684dae7243ce263f89
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at corya0687@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 corya0687
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Notes
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Building a Gem
|
2
|
+
1. Plan it, imagine interface
|
3
|
+
2. Start with the project structure
|
4
|
+
3. Start wit the entry point
|
5
|
+
4. force that to build the CLI interface
|
6
|
+
5. stub out the interface
|
7
|
+
6. start making things real
|
8
|
+
7. discover objects
|
9
|
+
8. program
|
10
|
+
|
11
|
+
Objects-
|
12
|
+
CLI
|
13
|
+
validator
|
14
|
+
scraper
|
15
|
+
product
|
16
|
+
searcher
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Arbitrage Finder
|
21
|
+
1. user enters zip code
|
22
|
+
2. User enters zipcode they want to buy in
|
23
|
+
3. user enters the zip code they want to sell in
|
24
|
+
4. Searches for buying opportunities on CL
|
25
|
+
4a. Displays list to pick
|
26
|
+
5. Searches for profit oppotunities using selection in selling zipcode
|
27
|
+
6. Returns list of possible arbitrage.
|
28
|
+
7. Enters which
|
29
|
+
|
30
|
+
additional features-
|
31
|
+
Arbitrage finder finds underpriced items and a profitable market
|
32
|
+
|
33
|
+
Log - Left off needing to connect url in nearby Craiglist, added to all array
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Arbitrage
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/arbitrage`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'arbitrage'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install arbitrage
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/arbitrage. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/arbitrage.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'arbitrage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "arbitrage"
|
8
|
+
spec.version = Arbitrage::VERSION
|
9
|
+
spec.authors = ["corya0687"]
|
10
|
+
spec.email = ["corya0687@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Finds profit opportunity on Craigslist}
|
13
|
+
spec.description = %q{CLI Gem that compares the price of a product in your local craigslist market to ones neaby and returns a potential profit report}
|
14
|
+
spec.homepage = "https://github.com/corya0687/arbitrage-cli-gem.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
#if spec.respond_to?(:metadata)
|
20
|
+
#spec.metadata['allowed_push_host'] = 'http://mygemserver.com'
|
21
|
+
## raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
#end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
end
|
data/bin/arbitrage
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "arbitrage"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/arbitrage.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
class Arbitrage::Scraper
|
2
|
+
attr_accessor :url, :product, :buy_options
|
3
|
+
|
4
|
+
def create_index_url
|
5
|
+
csv_data = File.read('rsc/clzips.csv')
|
6
|
+
rows = csv_data.split("\n")
|
7
|
+
people = rows.collect do |row|
|
8
|
+
data = row.split(",")
|
9
|
+
if data[1] == self.product.zipcode
|
10
|
+
self.url=data[0]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_product_list
|
16
|
+
html = open(craigslist_search_url(self.url,craigslist_query))
|
17
|
+
doc = Nokogiri::HTML(html)
|
18
|
+
buy_options_menu(doc)
|
19
|
+
display_buy_options
|
20
|
+
end
|
21
|
+
|
22
|
+
def buy_options_menu(doc)
|
23
|
+
self.buy_options = {}
|
24
|
+
doc.css('.row').each_with_index do |row, i|
|
25
|
+
if i < 11
|
26
|
+
self.buy_options["#{i+1}".to_s] = {
|
27
|
+
name: (row.css('.hdrlnk').text),
|
28
|
+
price: (row.css('.l2 .price').text),
|
29
|
+
url:"#{self.url}mod/#{(row.css('.pl a')[0]['data-id'])}.html"
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def display_buy_options
|
36
|
+
self.buy_options.each do |key, value|
|
37
|
+
puts "#{key}.#{value[:name]} for #{value[:price]}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def craigslist_query
|
42
|
+
query = self.product.name.split(" ")
|
43
|
+
if query.size > 1
|
44
|
+
query= query.join("%20")
|
45
|
+
else
|
46
|
+
query= query.join
|
47
|
+
end
|
48
|
+
self.product.query = query
|
49
|
+
end
|
50
|
+
|
51
|
+
def craigslist_search_url(url,query)
|
52
|
+
"#{url}search/sss?query=#{query}&sort=rel"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#CLI Controller
|
2
|
+
class Arbitrage::CLI
|
3
|
+
attr_accessor :validator, :market_value, :product, :profit
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.validator = Arbitrage::InputValidator.new
|
7
|
+
self.product = Arbitrage::Product.new
|
8
|
+
self.profit = Arbitrage::Profit.new(self.product)
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
puts "What's your zipcode?"
|
13
|
+
self.product.get_zipcode
|
14
|
+
self.product.get_product
|
15
|
+
puts "Details on the product you've selected:"
|
16
|
+
puts "______________________________________"
|
17
|
+
puts self.product.display_product_details
|
18
|
+
puts "______________________________________"
|
19
|
+
self.profit.list_opportunity
|
20
|
+
#puts "your potential profit on the sale of #{self.product.name} is $#{gross_profit}"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class Arbitrage::NearbyCraigslists
|
2
|
+
attr_accessor :scraper, :all_indexes, :original_product
|
3
|
+
|
4
|
+
def initialize(original_product,scraper)
|
5
|
+
self.scraper = scraper
|
6
|
+
self.all_indexes = []
|
7
|
+
self.original_product = original_product
|
8
|
+
end
|
9
|
+
|
10
|
+
def save_original_url
|
11
|
+
self.all_indexes << self.scraper.url
|
12
|
+
end
|
13
|
+
|
14
|
+
def save_all_indexes
|
15
|
+
next_two_craigslists
|
16
|
+
prev_two_craigslists
|
17
|
+
end
|
18
|
+
|
19
|
+
def next_two_craigslists
|
20
|
+
i=0
|
21
|
+
zipcode = self.original_product.zipcode.to_i
|
22
|
+
until i == 2
|
23
|
+
zipcode += 1
|
24
|
+
if !(url_stored?(zipcode)) && find_nearby_url(zipcode) != ""
|
25
|
+
self.all_indexes << find_nearby_url(zipcode)
|
26
|
+
i += 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def prev_two_craigslists
|
33
|
+
i=0
|
34
|
+
zipcode = self.original_product.zipcode.to_i
|
35
|
+
until i == 2
|
36
|
+
zipcode -= 1
|
37
|
+
if !(url_stored?(zipcode)) && find_nearby_url(zipcode) != ""
|
38
|
+
self.all_indexes << find_nearby_url(zipcode)
|
39
|
+
i += 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def url_stored?(zipcode)
|
45
|
+
self.all_indexes.any? do |current_url|
|
46
|
+
current_url == find_nearby_url(zipcode)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def find_nearby_url(zipcode)
|
51
|
+
nearby_url = ""
|
52
|
+
csv_data = File.read('rsc/clzips.csv')
|
53
|
+
rows = csv_data.split("\n")
|
54
|
+
people = rows.collect do |row|
|
55
|
+
data = row.split(",")
|
56
|
+
if data[1].to_i == zipcode
|
57
|
+
nearby_url= data[0]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
nearby_url
|
61
|
+
end
|
62
|
+
end
|