Created
October 5, 2014 11:16
-
-
Save balaam/b49ab90b820cfc482aa3 to your computer and use it in GitHub Desktop.
Twitter tools
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
| #!/opt/local/bin/lua | |
| dofile("./printtable.lua") | |
| dofile("./blacklist.lua") | |
| local BACKUP_PATH = "./backup/" | |
| function dofile (filename) | |
| local f = assert(loadfile(filename)) | |
| return f() | |
| end | |
| function is_valid_handle(str) | |
| if not str then return false end | |
| if string.sub(str, 1, 1) == '@' then | |
| str = string.sub(str, 2) | |
| end | |
| local len = string.len(str) | |
| return len > 0 and len <= 15 and string.match(str, "[a-z0-9_]+") == str | |
| end | |
| function write_file(path, data) | |
| local f = io.open(path, "w+") | |
| f:write(data) | |
| f:close() | |
| end | |
| function blacklist_to_str() | |
| local str = IterTable(blacklist or {}, nil, nil, DefaultPrinter) | |
| str = "blacklist = \n" .. str | |
| str = string.sub(str, 1, -3) .. '\n' | |
| return str | |
| end | |
| function write_blacklist() | |
| write_file("./blacklist.lua", blacklist_to_str()) | |
| end | |
| function back_up_id(str) | |
| return str .. os.date(".%Y_%m_%d_%H_%M_%S") | |
| end | |
| -- | |
| -- Backup blacklist | |
| -- | |
| write_file(string.format("%s%s", BACKUP_PATH, back_up_id("blacklist.lua")), | |
| blacklist_to_str()) | |
| blacklist["@test"] = true | |
| write_blacklist() | |
| PrintTable(blacklist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment