Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- component = require("component")
- detector = component.ir_augment_detector
- event = require("event")
- os = require("os")
- internet = require("internet")
- stationName = "grassland"
- url = "http://localhost:8011"
- while true do
- local _, _, _, uid = event.pull("ir_train_overhead")
- print(uid)
- if uid == nil then
- goto continue
- end
- local readHash= "abe6db4c9f5484fae8d79f2e868a673c"
- local handle, a1, a2 = internet.request(url .. "/showAll?passHash=" .. readHash)
- local result = ""
- for chunk in handle do
- result = result .. chunk
- end
- local uidParsed = uid:gsub("%-", "%%-")
- local search = string.find(result, uidParsed)
- if search == nil then
- print("Adding new train")
- local addHash = "abe6db4c9f5484fae8d79f2e868a673c"
- local handle = internet.request(url .. "/addTrain?tag=" .. uid.. "&passHash=" .. addHash .. "&station=" .. stationName)
- else
- print("Updating train")
- local updateHash = "abe6db4c9f5484fae8d79f2e868a673c"
- local handle = internet.request(url .. "/updateTrainByName?tag=" .. uid .. "&passHash=" .. updateHash .. "&station=" .. stationName)
- end
- os.sleep(1)
- ::continue::
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement