update_pos.lua
41 lines · 933 B
Copy & run
wget https://perlytiara.github.io/turtles.tips/raw/programs/BigGamingGamers/update_pos.lua
| 1 | local FILENAME = '/pos.lua' |
| 2 | |
| 3 | local cacheBreak = tostring(math.random(0, 99999)) |
| 4 | |
| 5 | res, err = http.get('https://gist.githubusercontent.com/Michael-Reeves808/825a0f20b4cce7c7b5b55f79944d1d44/raw/pos.lua?breaker=' .. cacheBreak) |
| 6 | if not res then error(err) end |
| 7 | |
| 8 | local code = res.readAll() |
| 9 | |
| 10 | |
| 11 | if not(fs.exists(FILENAME)) |
| 12 | then |
| 13 | local newHarvest = fs.open(FILENAME, 'w') |
| 14 | newHarvest.close() |
| 15 | end |
| 16 | |
| 17 | local readFile = fs.open(FILENAME, 'r') |
| 18 | local oldCode = readFile.readAll() |
| 19 | readFile.close() |
| 20 | |
| 21 | local file = fs.open(FILENAME, 'w') |
| 22 | |
| 23 | if oldCode == code |
| 24 | then |
| 25 | file.write(oldCode) |
| 26 | print('NO CHANGES MADE - Same Code') |
| 27 | else |
| 28 | file.write(code) |
| 29 | print('WRITING UPDATE') |
| 30 | byteDiff = string.len(code) - string.len(oldCode) |
| 31 | |
| 32 | if byteDiff >= 0 |
| 33 | then |
| 34 | print(tostring(math.abs(byteDiff)) .. ' bytes added') |
| 35 | else |
| 36 | print(tostring(math.abs(byteDiff)) .. ' bytes removed') |
| 37 | end |
| 38 | end |
| 39 | |
| 40 | file.close() |
| 41 | res.close() |