Show a random item (some silly Python)

Simple python code which outputs a random item from your document each time you run it.

I was just messing around to test out VSCode’s Jupyter notebook mode + Github Copilot both of which are pretty nice. I couldn’t really do much with the document other than flatten it fully using the content field. The nested hierarchy is too scrambled for me to figure out otherwise.

import requests
import json
from random import random


token="BiGcHuNgUs420"
file_id="FroMtHeDocUmEnTURL"

r=requests.post("https://dynalist.io/api/v1/doc/read", \
                json = {"token": token, "file_id": file_id})
doc_dict = r.json()
doc_list_of_dicts = doc_dict["nodes"]
dict1 = {}
str1 = ""

for i in range(len(doc_list_of_dicts)):
    str1 = str1 + doc_list_of_dicts[i]["content"] + "\n"

def random_int(min, max):
    return min + int(random() * (max - min))

random_item = str1.split("\n")[random_int(0, len(str1.split("\n")))]
print(random_item)
1 Like