mickael49300_fr

horloge paris v5

Apr 25th, 2023
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. -- Récupère l'heure et la date de Paris en temps réel
  2. function getParisDateTime()
  3. local url = "http://worldtimeapi.org/api/timezone/Europe/Paris"
  4. local response = http.get(url)
  5. local data = response.readAll()
  6. response.close()
  7. local time = textutils.unserializeJSON(data)
  8. local date = string.sub(time.datetime, 9, 10) .. "/" .. string.sub(time.datetime, 6, 7) .. "/" .. string.sub(time.datetime, 1, 4)
  9. local time = string.sub(time.datetime, 12, 19)
  10. return date, time
  11. end
  12.  
  13. -- Fonction pour ajuster la taille d'affichage en fonction du nombre de moniteurs
  14. function adjustDisplaySize(monitor)
  15. local size = #peripheral.getNames("monitor")
  16. if size == 0 then
  17. size = 1
  18. end
  19. monitor.setTextScale(math.floor(4 / size))
  20. end
  21.  
  22. -- Initialise le moniteur
  23. local monitor = peripheral.wrap("top")
  24. adjustDisplaySize(monitor)
  25. monitor.setTextColor(colors.white)
  26.  
  27. -- Boucle principale : affiche la date et l'heure de Paris en temps réel sur le moniteur
  28. while true do
  29. local date, time = getParisDateTime()
  30. monitor.clear()
  31. monitor.setCursorPos(1,1)
  32. monitor.write(date)
  33. monitor.setCursorPos(1,2)
  34. monitor.write(time)
  35. sleep(1)
  36. end
  37.  
Advertisement
Add Comment
Please, Sign In to add comment