Created
May 17, 2011 22:26
-
-
Save jessykate/977559 to your computer and use it in GitHub Desktop.
A quick and dirty way to check for new courses on the (new) P2PU site.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'net/smtp' | |
=begin | |
1. Download the file. | |
2. Make sure it is executable by running: | |
$ chmod +x newcourses.rb | |
3. Any time you want to check for new courses, just run: | |
$ ./newcourses.rb | |
=end | |
url = "http://new.p2pu.org/en/groups/" | |
File.exist?("courselist.txt")? old_list = File.read("courselist.txt") : old_list = "" | |
dir = ARGV[0] | |
page = %x[curl --silent #{url}] | |
courses = [] | |
new_courses = [] | |
page.each{|line| | |
course = line[/\/en\/groups\/[^"]*\//] | |
if course | |
courses << course | |
new_courses << course unless old_list[course] | |
end | |
} | |
unless new_courses.empty? | |
# append new courses to the saved courselist | |
new_courses = new_courses.uniq | |
File.open("courselist.txt", "a") {|f| | |
new_courses.each{|c| f.puts c } | |
} | |
# send an email with the changes | |
message = <<-MESSAGE_END | |
From: [email protected] | |
To: [email protected] | |
MIME-Version: 1.0 | |
Content-type: text/html | |
Subject: New Courses on new.P2PU.org | |
<h1>New Courses Since Yesterday</h1> | |
MESSAGE_END | |
new_courses.each{|c| | |
course_url = "http://new.p2pu.org#{c}" | |
message << "<a href=\"#{course_url}\">#{course_url}</a><br>\n" | |
} | |
Net::SMTP.start('localhost') do |smtp| | |
smtp.send_message message, '[email protected]', | |
'[email protected]' | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment