Advertisement
etelan

stationv1.5

Jan 27th, 2022 (edited)
951
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. component = require("component")
  2. detector = component.ir_augment_detector
  3. event = require("event")
  4. os = require("os")
  5. internet = require("internet")
  6.  
  7. stationName = "grassland"
  8.  
  9. url = "http://localhost:8011"
  10.  
  11. while true do
  12.   local _, _, _, uid = event.pull("ir_train_overhead")
  13.   print(uid)
  14.  
  15.   if uid == nil then
  16.     goto continue
  17.   end
  18.  
  19.   local readHash= "abe6db4c9f5484fae8d79f2e868a673c"
  20.   local handle, a1, a2 = internet.request(url .. "/showAll?passHash=" .. readHash)
  21.  
  22.  
  23.   local result = ""
  24.   for chunk in handle do
  25.     result = result .. chunk
  26.   end
  27.  
  28.   local uidParsed = uid:gsub("%-", "%%-")
  29.   local search = string.find(result, uidParsed)
  30.  
  31.   if search == nil then
  32.     print("Adding new train")
  33.     local addHash = "abe6db4c9f5484fae8d79f2e868a673c"
  34.     local handle = internet.request(url .. "/addTrain?tag=" .. uid.. "&passHash=" .. addHash .. "&station=" .. stationName)
  35.   else
  36.       print("Updating train")
  37.       local updateHash = "abe6db4c9f5484fae8d79f2e868a673c"
  38.       local handle = internet.request(url .. "/updateTrainByName?tag=" .. uid .. "&passHash=" .. updateHash .. "&station=" .. stationName)
  39.   end
  40.  
  41.   os.sleep(1)
  42.   ::continue::
  43. end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement