Advertisement
Guest User

Untitled

a guest
Dec 6th, 2022
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. a timer on renpy that checks time over the internet
  2.  
  3. init python:
  4.     import requests
  5.     import datetime
  6.  
  7.     # get current datetime from site
  8.     def get_worldtime():
  9.         res = None
  10.         try:
  11.             # get data from worldtimeapi.org
  12.             data = requests.get('http://worldtimeapi.org/api/timezone/Etc/UTC').json()["datetime"]
  13.             # convert string to datetime format
  14.             res = datetime.datetime.fromisoformat(data)
  15.         except requests.RequestException as e:
  16.             renpy.notify("Something wrong: " + str(e))
  17.         return res
  18.  
  19.     # using sample
  20.     def check_time():
  21.         world_now = get_worldtime().timestamp()
  22.         now = datetime.datetime.now().timestamp()
  23.         # do what you want
  24.         # ***
  25.         dt = now - world_now
  26.         renpy.notify(str(dt))
  27.  
  28. label start:
  29.     # test
  30.     # $ check_time()
  31.     # $ t = get_worldtime()
  32.     # "[t]"
  33.  
  34.     python:
  35.         now = datetime.datetime.now().timestamp()
  36.         world_now = get_worldtime().timestamp()
  37.         dt = now - world_now
  38.     $ xxx = str(dt)
  39.     "No pause: [xxx]"
  40.  
  41.     python:
  42.         now = datetime.datetime.now().timestamp()
  43.         renpy.pause(2)
  44.         world_now = get_worldtime().timestamp()
  45.         dt = now - world_now
  46.     $ xxx = str(dt)
  47.     "With pause: [xxx]"
  48.  
  49.     return
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement