public
Description: Ruby script that takes data from the BBC website and sends it to twitter/pollen_london
Homepage: http://twitter.com/pollen_london
Clone URL: git://github.com/snowblink/pollen-london.git
pollen-london / pollen.rb
100755 50 lines (40 sloc) 1.226 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env ruby
#
# Created by Jonathan Lim on 2008-05-13.
# Copyright (c) 2008. All rights reserved.
 
# Twitter pollen updates
 
# $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
 
require 'rubygems'
require 'open-uri'
gem 'twitter4r'
require 'twitter'
require 'hpricot'
require 'yaml'
 
Twitter::Client.configure do |conf|
  conf.application_name = 'PollenLondonBot'
  conf.application_version = '0.4'
  conf.application_url = 'https://github.com/snowblink/pollen-london/tree'
  conf.source = 'pollenlondon'
end
 
twitter_config = YAML::load_file(File.dirname(__FILE__) + '/twitter_config.yml')
twitter = Twitter::Client.new(twitter_config)
 
date = DateTime.now.strftime("%A %Y%m%d")
 
# load BBC Pollen site
doc = Hpricot(open("http://news.bbc.co.uk/weather/forecast/8/UV.xhtml"))
 
elements = doc.search("li")
to_twitter = []
 
elements.each do |element|
  if element.get_attribute("class") == 'pollenval'
    to_twitter << element.at("img").get_attribute("alt") + ' (' + Time.now.gmtime.strftime("%a %d/%m") + ')'
  end
end
 
to_twitter.each do |update|
  begin
    twitter.status(:post, update)
    # puts update
  rescue Exception => e
    puts "FAILED!"
    puts e
    exit 1
  end
end