Skip to content

Commit

Permalink
Set number of storage slots in the script. Fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
rrw4 committed Nov 1, 2014
1 parent 9979a93 commit 825fa02
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ Usage:
- Set the players to track in the players table, and which sport (NFL/NBA/MLB) in the HTTP request params url.
- Set the email_notification and text_notification options to send via email and/or text.
- Run the script as a cron job every 1 minute, or however often you want to check for updates.
- Note that if more than 3 updates for tracked players are posted within a 15 update sequence (each scrape of Rotoworld's updates will grab last 15 updates), then repeats will be sent. The script can be easily modified to add more slots, but it generally won't be an issue unless you're tracking a lot of players. I don't think it's possible to programmatically set a storage key or iterate through storage key-values in webscript.io, so additional slots will have to be added one by one in the process_data() function.
27 changes: 14 additions & 13 deletions rotoworld_webscript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ local smtp_username = storage.smtp_username
local smtp_password = storage.smtp_password
local smtp_from_email = storage.smtp_from_email
local my_email = storage.my_email
local storage_count = 15

-- Processing functions
function str_clean(str)
Expand All @@ -35,9 +36,11 @@ function str_clean(str)
return string.sub(str, a1, string.len(str)-b1+1)
end

function update_last_slot()
function get_next_slot()
-- returns next slot and updates storage.last_slot
storage.last_slot = tonumber(storage.last_slot) + 1
if tonumber(storage.last_slot) > 3 then storage.last_slot = 1 end
if tonumber(storage.last_slot) > storage_count then storage.last_slot = 1 end
return storage.last_slot
end

function send_notifications(name, news)
Expand Down Expand Up @@ -65,18 +68,16 @@ function process_data(data)
player_news = data[2]
for k, v in pairs(players) do
if v == player_name then
-- Three slot "memory"
if storage.news1 ~= player_news and
storage.news2 ~= player_news and
storage.news3 ~= player_news then
if tonumber(storage.last_slot) == 1 then
storage.news2 = player_news
elseif tonumber(storage.last_slot) == 2 then
storage.news3 = player_news
else
storage.news1 = player_news
existing_update = false
for i = 1, storage_count do
if storage["rotoworld:" .. storage_count] == player_news then
existing_update = true
break
end
update_last_slot()
end

if existing_update == false then
storage["rotoworld:" .. get_next_slot()] = player_news
send_notifications(player_name, player_news)
end
end
Expand Down
4 changes: 4 additions & 0 deletions storage_reset.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
storage_count = 15
for i = 1, storage_count do
storage["rotoworld" .. storage_count] = ""
end
storage.news1 = ""
storage.news2 = ""
storage.news3 = ""
Expand Down

0 comments on commit 825fa02

Please sign in to comment.