Skip to content

Instantly share code, notes, and snippets.

@RohitRox
Last active December 15, 2015 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RohitRox/5264599 to your computer and use it in GitHub Desktop.
Save RohitRox/5264599 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'capybara'
require 'capybara/dsl'
require 'pry'
require 'yaml'
require 'json'
require "net/http"
require "uri"
Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'https://post.craigslist.org/'
# CONFIG = YAML.load(File.read("config.yml"))
CONFIG = {'host' => '64.187.124.250', 'port' => '400'}
class Connector
class << self
attr_accessor :dialer, :ads
def connect
poster = "http://#{CONFIG['host']}:#{CONFIG['port']}/ws.php?action=get_dialer_ip"
ads = "http://#{CONFIG['host']}:#{CONFIG['port']}/ws.php?action=get_schedule"
uri = URI.parse(poster)
response = Net::HTTP.get_response(uri)
@dialer = JSON.parse(response.body)
uri = URI.parse(ads)
response = Net::HTTP.get_response(uri)
@ads = JSON.parse(response.body)
end
end
end
module CragCapybara
class Crager
include Capybara::DSL
def post(params)
puts "-------- processing params --------"
puts params
visit 'https://post.craigslist.org/k/ilCA1wuX4hGR-BDgZ2Z2Og/mZo19?s=type'
page.all(:xpath,"//input[@value='#{params['mcat']}']").first.click
click_button('I will abide by these guidelines') if page.has_content?('I will abide by these guidelines')
page.all(:xpath,"//input[@value='#{params['scat']}']").first.click
case params['mcat']
when 'jo'
self.handle_jo(params)
when 'so'
self.handle_so(params)
else
puts 'Unexpected main category'
exit
end
puts "-----------------------------------"
end
def handle_jo(params)
els = page.all('input')
sleep(2)
title_el = els[0]
title_el.set params['title']
location_el = els[1]
location_el.set params['location']
sleep(2)
email_el = els[2]
email_el.set params['username']
again_email_el = els[3]
again_email_el.set params['username']
desc_el = page.all('textarea').first
desc_el.set params['body']
sleep(2)
# compen_el = els[7]
# compen_el.set "bonus salary"
# check('contract')
click_button "Continue"
end
def handle_so(params)
els = page.all('input')
sleep(2)
title_el = els[0]
title_el.set params['title']
location_el = els[1]
location_el.set params['location']
sleep(2)
email_el = els[2]
email_el.set params['username']
again_email_el = els[3]
again_email_el.set params['username']
desc_el = page.all('textarea').first
desc_el.set params['body']
sleep(2)
click_button "Continue"
end
def self.run
Connector.connect
craigslister = self.new
puts 'Connecting .... '
puts 'Got Ads: '
puts Connector.ads
Connector.ads['schedules'].each do |ads|
craigslister.post(ads)
end
end
end
end
CragCapybara::Crager.run
# {
# "status"=>true, "schedules"=>
# [{"schedule_id"=>2460,
# "account_id"=>"232",
# "username"=>"trimqef@gmail.com",
# "password"=>"sumountepndh3pxja",
# "mac"=>"00:60:6A:C6:12:D6",
# "title"=>"* * * WE ALWAYS GO EXTRA MILE FOR OUR CUSTOMERS. LICENSED+INSURED * * *",
# "location"=>"100% BONDED/LICENSED",
# "body"=>"<p align=\"center\"> =>> Fast Pick-up & Delivery <B><BR> =>> Wardrobe boxes & Shrink wraps & Blankets & Tapes and more.. <B><BR> =>> Never a hidden charges.Never use day labors. <B><BR> =>> Professional movers.Fast & Reliable <B><BR> =>> Short notice moves welcome. <B><BR> =>> Expert Disassemble/Re-Assemble. <B><BR> =>> Time starts at your door & On time. <B><BR> =>> Great References upon request. <B><BR> =>> We guarantee you will be Happy & Satisfy <B><BR>",
# "zip"=>"33127",
# "image_filename"=>"tablemiami.JPG",
# "image"=>"http://64.187.124.250:400/tmp/img/tablemiami.JPG",
# "city"=>"mia",
# "scat"=>"82",
# "mcat"=>"so",
# "county"=>1,
# "county_string"=>"dade"
# }]
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment