MrKey2b

timetest

Oct 19th, 2023 (edited)
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. local moniteur = peripheral.wrap("top")
  2.  
  3. function obtenirDateHeureAPI()
  4.     local response = http.get("https://worldtimeapi.org/api/timezone/Europe/Paris")
  5.     if response then
  6.         local data = response.readAll()
  7.         response.close()
  8.         local heure = textutils.unserializeJSON(data)
  9.         local date = heure.datetime:sub(1, 10)
  10.         local heureFormattee = heure.datetime:sub(12, 19)
  11.         return date, heureFormattee
  12.     else
  13.         return "Erreur de connexion à l'API"
  14.     end
  15. end
  16.  
  17. function defilerTexte(texte, largeur)
  18.     local texteDefile = texte
  19.     while #texteDefile < largeur do
  20.         texteDefile = texteDefile .. " " .. texte
  21.     end
  22.  
  23.     local largeurTexte = #texteDefile
  24.     local position = 1
  25.     local direction = 1
  26.  
  27.     while true do
  28.         local texteAffiche = texteDefile:sub(position, position + largeur - 1)
  29.         moniteur.setCursorPos(1, 4)
  30.         moniteur.write(texteAffiche)
  31.  
  32.         position = position + direction
  33.         if position + largeur > largeurTexte then
  34.             position = 1
  35.             sleep(2)
  36.         else
  37.             sleep(0.5)
  38.         end
  39.     end
  40. end
  41.  
  42. parallel.waitForAll(
  43.     function()
  44.         while true do
  45.             local date, heure = obtenirDateHeureAPI()
  46.             moniteur.setCursorPos(1, 1)
  47.             moniteur.write("" .. heure)
  48.             moniteur.setCursorPos(1, 2)
  49.             moniteur.write("" .. date)
  50.             sleep(1)
  51.         end
  52.     end,
  53.     function()
  54.         local texteDefile = {
  55.             "Defqon.1 2024 : Power Of The Tribe",
  56.             "Le nain va-t'il se connecté ?",
  57.             "Oh un Nain !  Shorty sort de la !",
  58.             "Timy Bourré ?",
  59.             "Super Mr, Super Mr.. ",
  60.             "Smacko es ses licorne ^^",
  61.             "Hum Az_hog..",
  62.             "Un Noichi ? NAN",
  63.         }
  64.         local largeurTexte = 30
  65.         local indexTexte = 1
  66.  
  67.         while true do
  68.             defilerTexte(texteDefile[indexTexte], largeurTexte)
  69.             indexTexte = (indexTexte % #texteDefile) + 1
  70.             sleep(600)
  71.         end
  72.     end
  73. )
  74.  
Advertisement
Add Comment
Please, Sign In to add comment