lloydpick-toast 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/toast.rb +7 -8
- metadata +1 -1
data/lib/toast.rb
CHANGED
@@ -63,14 +63,14 @@ module Toast
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def toast!
|
66
|
-
File.delete("toast.db")
|
66
|
+
#File.delete("toast.db")
|
67
67
|
db = SQLite3::Database.new("toast.db")
|
68
68
|
db.execute("CREATE TABLE IF NOT EXISTS toasters (
|
69
69
|
id integer PRIMARY KEY,
|
70
70
|
frequency integer,
|
71
71
|
last_check datetime,
|
72
72
|
conditions varchar2(32),
|
73
|
-
complete
|
73
|
+
complete integer
|
74
74
|
);")
|
75
75
|
db.execute("CREATE TABLE IF NOT EXISTS breads (
|
76
76
|
id integer PRIMARY KEY,
|
@@ -143,7 +143,7 @@ module Toast
|
|
143
143
|
",
|
144
144
|
"frequency" => self.timer,
|
145
145
|
"conditions" => butters.join(","),
|
146
|
-
"complete" =>
|
146
|
+
"complete" => 0,
|
147
147
|
"last_check" => Time.now
|
148
148
|
);
|
149
149
|
|
@@ -155,7 +155,7 @@ module Toast
|
|
155
155
|
db = SQLite3::Database.new("toast.db")
|
156
156
|
|
157
157
|
db.results_as_hash = true
|
158
|
-
db.execute("select * from toasters where complete =
|
158
|
+
db.execute("select * from toasters where complete = 0") do |row|
|
159
159
|
if ((Time.parse(row["last_check"]) + row["frequency"].to_i) < Time.now)
|
160
160
|
row["conditions"].split(",")
|
161
161
|
row["conditions"].each do |condition|
|
@@ -166,13 +166,12 @@ module Toast
|
|
166
166
|
httpauth = Twitter::HTTPAuth.new(twitter["twitter_username"], twitter["twitter_password"])
|
167
167
|
base = Twitter::Base.new(httpauth)
|
168
168
|
base.update(twitter["twitter_message"])
|
169
|
-
db.execute("update toasters set
|
170
|
-
"last_check" => Time.now, "id" => row["id"], "outcome" => true)
|
169
|
+
db.execute("update toasters set complete = \"1\" where id = :id;", "id" => row["id"])
|
171
170
|
end
|
172
171
|
else
|
173
172
|
# Did'nt pass the condition, so update the time
|
174
|
-
db.execute("update toasters set last_check = :
|
175
|
-
"
|
173
|
+
db.execute("update toasters set last_check = :lastcheck where id = :id",
|
174
|
+
"lastcheck" => Time.now, "id" => row["id"])
|
176
175
|
end
|
177
176
|
end
|
178
177
|
end
|