Skip to content

Writing Python Scripts

Simple Hello World Example

print("hello world")

Every time the script is executed, it will print "hello world" to stdout. Thus subscribed users will receive "hello world" message every time the script is executed.

Getting Saved Data

Saved data written by the previous execution will be placed to /saved_data.json file in the execution environment. The file will be strings to string valid json object. You can directly read this file or use the regularbot Python package to read the saved data. Do not forget to add regularbot dependency when using regularbot package.

import regularbot

saved_data: dict[str, str] = regularbot.load_saved_data()
with open("/saved_data.json", "r") as f:
    saved_data: dict[str, str] = json.load(f)

Writing Saved Data

You should dump the new saved data to /saved_data.json file in the execution environment. If you did not make any change to the saved data, the received saved data will be used as the new saved data.

import regularbot

regularbot.save_data({"key": "value"})
with open("/saved_data.json", "w") as f:
    json.dump({"key": "value"}, f)