Guest User

Untitled

a guest
Jul 13th, 2018
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. thufir@ARRAKIS:~/rb$
  2. thufir@ARRAKIS:~/rb$
  3. thufir@ARRAKIS:~/rb$ ruby rss2mysql.rb
  4. rss2mysql.rb:32: syntax error, unexpected kOR, expecting ')'
  5. or Items.find_by_url(feed_item.link)
  6. ^
  7. rss2mysql.rb:33: syntax error, unexpected kOR, expecting ')'
  8. or Items.find_by_guid(feed_item.guid))
  9. ^
  10. rss2mysql.rb:52: syntax error, unexpected $end, expecting kEND
  11. thufir@ARRAKIS:~/rb$
  12. thufir@ARRAKIS:~/rb$ cat rss2mysql.rb
  13. require 'active_record'
  14. require 'feed_tools'
  15. feed_url = ARGV[0]
  16. # This call creates a connection to our database.
  17. ActiveRecord::Base.establish_connection(
  18. :adapter => "mysql",
  19. :host => "127.0.0.1",
  20. :username => "ruby", # Note that while this is the default setting for MySQL,
  21. :password => "password", # a properly secured system will have a different MySQL
  22. # username and password, and if so, you'll need to
  23. # change these settings.
  24. :database => "rss2mysql")
  25. class Items < ActiveRecord::Base
  26. end
  27. # If the table doesn't exist, we'll create it.
  28. unless Items.table_exists?
  29. ActiveRecord::Schema.define do
  30. create_table :items do |t|
  31. t.column :title, :string
  32. t.column :content, :string
  33. t.column :source, :string
  34. t.column :url, :string
  35. t.column :timestamp, :timestamp
  36. t.column :keyword_id, :integer
  37. t.column :guid, :string
  38. end
  39. end
  40. end
  41. feed=FeedTools::Feed.open(feed_url)
  42. feed.items.each do |feed_item|
  43. if not (Items.find_by_title(feed_item.title)
  44. or Items.find_by_url(feed_item.link)
  45. or Items.find_by_guid(feed_item.guid))
  46. puts "processing item '#{feed_item.title}' - new"
  47.  
  48. Items.new do |newitem|
  49. newitem.title=feed_item.title.gsub(/<[^>]*>/, '')
  50. newitem.guid=feed_item.guid
  51. if feed_item.publisher.name
  52. newitem.source=feed_item.publisher.name
  53. end
  54. newitem.url=feed_item.link
  55. newitem.content=feed_item.description
  56. newitem.timestamp=feed_item.published
  57. newitem.save
  58. end
  59. else
  60. puts "processing item '#{feed_item.title}' - old"
  61. end
  62. #end
  63.  
  64.  
  65. thufir@ARRAKIS:~/rb$
  66. thufir@ARRAKIS:~/rb$
Add Comment
Please, Sign In to add comment