Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Stash sqlite hacking.

  • Loading branch information...
commit 9079b9559a5334cb180bc65c3ddd384c1f638e28 1 parent 8155a51
@alloy alloy authored
View
3  INSTALL
@@ -0,0 +1,3 @@
+* git update --init
+* ruby19 ./bin/init
+* ruby19 ./bin/update-active-tickets
View
16 bin/init
@@ -0,0 +1,16 @@
+require "fileutils"
+require "rubygems"
+require "sequel"
+
+db = File.expand_path('../../data/db.sqlite3', __FILE__)
+FileUtils.mkdir_p(File.dirname(db))
+DB = Sequel.sqlite(db)
+
+DB.create_table :tickets do
+ Integer :id, :primary_key => true
+ String :link
+ String :summary, :text => true
+ String :assigned_to
+ FalseClass :marked_for_review
+ FalseClass :closed
+end
View
37 bin/update-active-tickets
@@ -0,0 +1,37 @@
+require "fileutils"
+require "rubygems"
+require "sequel"
+
+$:.unshift File.expand_path("../../vendor/simple-rss/lib", __FILE__)
+require "simple-rss"
+
+db = File.expand_path('../../data/db.sqlite3', __FILE__)
+FileUtils.mkdir_p(File.dirname(db))
+DB = Sequel.sqlite(db)
+
+class Ticket < Sequel::Model
+end
+
+#fixture = File.expand_path('../../spec/fixtures/trac_active_tickets_rss.xml', __FILE__)
+fixture = File.expand_path('../../spec/fixtures/trac_active_tickets_rss-minus-19-and-81.xml', __FILE__)
+raw_feed = File.read(fixture)
+
+rss = SimpleRSS.parse(raw_feed)
+ids = Ticket.filter(:closed => false).select(:id).all.map(&:id)
+seen = []
+
+rss.entries.each do |entry|
+ id = File.basename(entry[:link]).to_i
+ seen << id
+ unless Ticket.filter(:id => id).first
+ puts "does not exist!"
+ Ticket.insert(:id => id, :link => entry[:link], :summary => CGI.unescapeHTML(entry[:title]), :marked_for_review => false, :closed => false)
+ end
+end
+
+removed = ids - seen
+p removed
+
+removed.each do |id|
+ Ticket.filter(:id => id).update(:closed => true)
+end
View
27 lib/macruby_bugmash_bot/db.rb
@@ -0,0 +1,27 @@
+require "rubygems"
+require "sequel"
+
+# connect to an in-memory database
+DB = Sequel.sqlite(File.expand_path('../../../data/db.sqlite3', __FILE__))
+
+# create an items table
+#DB.create_table :items do
+ #primary_key :id
+ #String :name
+ #Float :price
+#end
+
+# create a dataset from the items table
+items = DB[:items]
+
+# populate the table
+#items.insert(:name => 'abc', :price => rand * 100)
+#items.insert(:name => 'def', :price => rand * 100)
+#items.insert(:name => 'ghi', :price => rand * 100)
+
+# print out the number of records
+puts "Item count: #{items.count}"
+
+# print out the average price
+puts "The average price is: #{items.avg(:price)}"
+
Please sign in to comment.
Something went wrong with that request. Please try again.