intake-sources/intake-echo/intake_echo/core.py

23 lines
431 B
Python
Raw Normal View History

2023-06-25 04:45:23 +00:00
import hashlib
import json
import os
import random
def main():
item = {}
title = os.environ.get("TITLE", "Hello, world!")
if os.environ.get("UNIQUE"):
item["id"] = hashlib.md5(title.encode("utf8")).hexdigest()
else:
item["id"] = "{:x}".format(random.getrandbits(16 * 4))
item["title"] = title
if body := os.environ.get("BODY"):
item["body"] = body
print(json.dumps(item))