Skip to content

Instantly share code, notes, and snippets.

@audy
Created August 14, 2011 21:09
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 audy/1145309 to your computer and use it in GitHub Desktop.
Save audy/1145309 to your computer and use it in GitHub Desktop.
craigslist twitter bot
require 'open-uri'
require 'nokogiri'
require 'chatterbot/dsl'
url = 'http://gainesville.craigslist.org/zip/'
bot = Chatterbot::Bot.new
posts = Array.new
tweet_log = File.open('tweeted.txt', 'a')
loop do
puts "Checking Craigslist: #{Time.now}"
tweeted = File.open('tweeted.txt').readlines.collect { |x| x.strip }
doc = Nokogiri::HTML(open(url))
doc.css('.row > a').each do |item|
url = item['href']
name = item.content
posts << [name, url.to_s]
end
posts.each do |desc, url|
tweet = "#{desc}, #{url}"
unless tweeted.include? url
tweet msg
puts msg
tweet_log.puts url
end
end
sleep 240
end
tweet_log.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment