Created
May 6, 2013 14:45
-
-
Save everdaniel/5525604 to your computer and use it in GitHub Desktop.
Generate a CSV file with all projects listed at Embarcadero App Showcase
This file contains hidden or 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
| require "mechanize" | |
| require "csv" | |
| agent = Mechanize.new | |
| page = agent.get("http://www.embarcadero.com/index.php?option=com_mmportfolio&view=projects&layout=appshowcase&format=raw") | |
| projects = [] | |
| page.search("div.appitem").each do |item| | |
| puts "Fetching: " + item.text | |
| id = item["rel"] | |
| name = item.text | |
| image_small = "http://www.embarcadero.com" + item["style"].split("(")[1].split(")")[0] | |
| image_large = "http://www.embarcadero.com" + item["style"].split("(")[1].split(")")[0].gsub("/small/", "/large/") | |
| category = nil | |
| date_added = nil | |
| developer = nil | |
| developer_url = nil | |
| description = nil | |
| agent.get("http://www.embarcadero.com/index.php?option=com_mmportfolio&view=project&format=raw&id=" + id) do |detail| | |
| puts "|-> Fetching detail: " + item.text | |
| category = detail.search('#category-title').first().text().split(':')[1].strip() | |
| date_parts = detail.search('#publish-up').first().text().gsub(",", "") | |
| date_added = date_parts[0] + "/" + date_parts[2] + "/" + date_parts[3] | |
| developer = detail.search('#site-url').first().text().strip() | |
| developer_url = detail.search('#site-url').first()["href"].strip() | |
| description = detail.search('#description').first().text().gsub("Description:", "").gsub("/[\r\n\t]/", "").strip() | |
| end | |
| projects << [id, name, image_small, image_large, category, date_added, developer, developer_url, description] | |
| end | |
| puts projects | |
| csv_file = Dir.pwd + "/projects_list.csv" | |
| CSV.open(csv_file, "w") do |csv| | |
| csv << ["id", "name", "image_small", "image_large", "category", "date_added", "developer", "developer_url", "description"] | |
| projects.each do |project| | |
| csv << project | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment