Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a timer on renpy that checks time over the internet
- init python:
- import requests
- import datetime
- # get current datetime from site
- def get_worldtime():
- res = None
- try:
- # get data from worldtimeapi.org
- data = requests.get('http://worldtimeapi.org/api/timezone/Etc/UTC').json()["datetime"]
- # convert string to datetime format
- res = datetime.datetime.fromisoformat(data)
- except requests.RequestException as e:
- renpy.notify("Something wrong: " + str(e))
- return res
- # using sample
- def check_time():
- world_now = get_worldtime().timestamp()
- now = datetime.datetime.now().timestamp()
- # do what you want
- # ***
- dt = now - world_now
- renpy.notify(str(dt))
- label start:
- # test
- # $ check_time()
- # $ t = get_worldtime()
- # "[t]"
- python:
- now = datetime.datetime.now().timestamp()
- world_now = get_worldtime().timestamp()
- dt = now - world_now
- $ xxx = str(dt)
- "No pause: [xxx]"
- python:
- now = datetime.datetime.now().timestamp()
- renpy.pause(2)
- world_now = get_worldtime().timestamp()
- dt = now - world_now
- $ xxx = str(dt)
- "With pause: [xxx]"
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement