Add gen and fortune tools - gen.py: Password, UUID, lorem, hash, random, slug, timestamp - fortune.py: Random wisdom and daily fortune - 33 tools total!
This commit is contained in:
@ -19,6 +19,11 @@
|
||||
"value": 31.0,
|
||||
"timestamp": "2026-01-30T23:57:21.461144",
|
||||
"note": "Midnight push"
|
||||
},
|
||||
{
|
||||
"value": 33.0,
|
||||
"timestamp": "2026-01-30T23:58:26.472974",
|
||||
"note": "Past midnight"
|
||||
}
|
||||
],
|
||||
"created": "2026-01-30T23:54:10.266015"
|
||||
|
||||
126
tools/fortune.py
Executable file
126
tools/fortune.py
Executable file
@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
fortune - Random wisdom and fortune
|
||||
|
||||
Combines wisdom collection with classic fortune vibes.
|
||||
"""
|
||||
|
||||
import json
|
||||
import random
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
WORKSPACE = Path("/home/wdjones/.openclaw/workspace")
|
||||
WISDOM_FILE = WORKSPACE / "data" / "wisdom.json"
|
||||
|
||||
# Built-in fortunes if wisdom is empty
|
||||
FORTUNES = [
|
||||
"The best time to start was yesterday. The second best time is now.",
|
||||
"Simple is better than complex.",
|
||||
"Done is better than perfect.",
|
||||
"You are not your code.",
|
||||
"First, solve the problem. Then, write the code.",
|
||||
"Code is read more often than it is written.",
|
||||
"The only way to go fast is to go well.",
|
||||
"Make it work, make it right, make it fast.",
|
||||
"Weeks of coding can save you hours of planning.",
|
||||
"There are only two hard things in CS: cache invalidation and naming things.",
|
||||
"It works on my machine!",
|
||||
"The quieter you become, the more you can hear.",
|
||||
"What you do today is important because you're exchanging a day of your life for it.",
|
||||
"The obstacle is the way.",
|
||||
"We suffer more in imagination than in reality.",
|
||||
"Focus on what you can control.",
|
||||
"The impediment to action advances action. What stands in the way becomes the way.",
|
||||
"You have power over your mind, not outside events.",
|
||||
"Think of yourself as dead. Now take what's left and live it properly.",
|
||||
"If it is not right, do not do it. If it is not true, do not say it.",
|
||||
]
|
||||
|
||||
def load_wisdom() -> list:
|
||||
"""Load wisdom entries."""
|
||||
if WISDOM_FILE.exists():
|
||||
try:
|
||||
with open(WISDOM_FILE) as f:
|
||||
data = json.load(f)
|
||||
return [w['text'] for w in data]
|
||||
except:
|
||||
pass
|
||||
return []
|
||||
|
||||
def fortune():
|
||||
"""Get a random fortune."""
|
||||
# Combine wisdom and built-in fortunes
|
||||
wisdom = load_wisdom()
|
||||
all_fortunes = FORTUNES + wisdom
|
||||
|
||||
selected = random.choice(all_fortunes)
|
||||
|
||||
width = min(60, max(len(selected), 40))
|
||||
|
||||
print()
|
||||
print("╭" + "─" * (width + 2) + "╮")
|
||||
|
||||
# Word wrap
|
||||
words = selected.split()
|
||||
lines = []
|
||||
current = ""
|
||||
for word in words:
|
||||
if len(current) + len(word) + 1 <= width:
|
||||
current = current + " " + word if current else word
|
||||
else:
|
||||
lines.append(current)
|
||||
current = word
|
||||
if current:
|
||||
lines.append(current)
|
||||
|
||||
for line in lines:
|
||||
print(f"│ {line:<{width}} │")
|
||||
|
||||
print("╰" + "─" * (width + 2) + "╯")
|
||||
print()
|
||||
|
||||
def daily_fortune():
|
||||
"""Get today's fortune (consistent for the day)."""
|
||||
wisdom = load_wisdom()
|
||||
all_fortunes = FORTUNES + wisdom
|
||||
|
||||
# Seed with today's date
|
||||
day_seed = int(datetime.now().strftime("%Y%m%d"))
|
||||
random.seed(day_seed)
|
||||
selected = random.choice(all_fortunes)
|
||||
random.seed()
|
||||
|
||||
print("\n🌅 Today's Fortune:")
|
||||
|
||||
width = min(60, max(len(selected), 40))
|
||||
print("─" * (width + 4))
|
||||
|
||||
words = selected.split()
|
||||
lines = []
|
||||
current = ""
|
||||
for word in words:
|
||||
if len(current) + len(word) + 1 <= width:
|
||||
current = current + " " + word if current else word
|
||||
else:
|
||||
lines.append(current)
|
||||
current = word
|
||||
if current:
|
||||
lines.append(current)
|
||||
|
||||
for line in lines:
|
||||
print(f" {line}")
|
||||
|
||||
print("─" * (width + 4))
|
||||
print()
|
||||
|
||||
def main():
|
||||
import sys
|
||||
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'daily':
|
||||
daily_fortune()
|
||||
else:
|
||||
fortune()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
146
tools/gen.py
Executable file
146
tools/gen.py
Executable file
@ -0,0 +1,146 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
gen - Content generators
|
||||
|
||||
Generate passwords, UUIDs, lorem ipsum, and more.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import random
|
||||
import string
|
||||
import uuid
|
||||
import hashlib
|
||||
from datetime import datetime
|
||||
|
||||
LOREM = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."""
|
||||
|
||||
WORDS = LOREM.replace(',', '').replace('.', '').lower().split()
|
||||
|
||||
def password(length: int = 16, simple: bool = False):
|
||||
"""Generate a secure password."""
|
||||
if simple:
|
||||
chars = string.ascii_letters + string.digits
|
||||
else:
|
||||
chars = string.ascii_letters + string.digits + "!@#$%^&*"
|
||||
|
||||
pwd = ''.join(random.choice(chars) for _ in range(length))
|
||||
print(pwd)
|
||||
|
||||
def gen_uuid():
|
||||
"""Generate a UUID."""
|
||||
print(uuid.uuid4())
|
||||
|
||||
def lorem(words: int = 50):
|
||||
"""Generate lorem ipsum text."""
|
||||
output = []
|
||||
for i in range(words):
|
||||
word = random.choice(WORDS)
|
||||
if i == 0 or output[-1].endswith('.'):
|
||||
word = word.capitalize()
|
||||
output.append(word)
|
||||
|
||||
# Add periods
|
||||
text = ' '.join(output)
|
||||
# Every ~10 words add punctuation
|
||||
words_list = text.split()
|
||||
result = []
|
||||
for i, word in enumerate(words_list):
|
||||
result.append(word)
|
||||
if (i + 1) % random.randint(8, 12) == 0 and i < len(words_list) - 1:
|
||||
if random.random() < 0.7:
|
||||
result[-1] += '.'
|
||||
else:
|
||||
result[-1] += ','
|
||||
|
||||
print(' '.join(result) + '.')
|
||||
|
||||
def hash_text(text: str, algorithm: str = 'sha256'):
|
||||
"""Hash some text."""
|
||||
if algorithm == 'md5':
|
||||
h = hashlib.md5(text.encode()).hexdigest()
|
||||
elif algorithm == 'sha1':
|
||||
h = hashlib.sha1(text.encode()).hexdigest()
|
||||
else:
|
||||
h = hashlib.sha256(text.encode()).hexdigest()
|
||||
print(h)
|
||||
|
||||
def random_number(min_val: int = 1, max_val: int = 100):
|
||||
"""Generate a random number."""
|
||||
print(random.randint(min_val, max_val))
|
||||
|
||||
def random_choice(options: list):
|
||||
"""Pick a random option."""
|
||||
choice = random.choice(options)
|
||||
print(f"🎲 {choice}")
|
||||
|
||||
def slug(text: str):
|
||||
"""Generate a URL slug from text."""
|
||||
slug = text.lower()
|
||||
slug = ''.join(c if c.isalnum() or c == ' ' else '' for c in slug)
|
||||
slug = '-'.join(slug.split())
|
||||
print(slug)
|
||||
|
||||
def timestamp():
|
||||
"""Generate current timestamp."""
|
||||
now = datetime.now()
|
||||
print(f"ISO: {now.isoformat()}")
|
||||
print(f"Unix: {int(now.timestamp())}")
|
||||
print(f"Date: {now.strftime('%Y-%m-%d')}")
|
||||
print(f"Time: {now.strftime('%H:%M:%S')}")
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage:")
|
||||
print(" gen pass [length] - Generate password")
|
||||
print(" gen pass simple [n] - Simple password (no symbols)")
|
||||
print(" gen uuid - Generate UUID")
|
||||
print(" gen lorem [words] - Lorem ipsum text")
|
||||
print(" gen hash <text> - SHA256 hash")
|
||||
print(" gen rand [min] [max] - Random number")
|
||||
print(" gen pick <options> - Random choice")
|
||||
print(" gen slug <text> - URL slug")
|
||||
print(" gen time - Current timestamps")
|
||||
return
|
||||
|
||||
cmd = sys.argv[1]
|
||||
|
||||
if cmd in ['pass', 'password', 'pw']:
|
||||
simple = 'simple' in sys.argv
|
||||
length = 16
|
||||
for arg in sys.argv[2:]:
|
||||
if arg.isdigit():
|
||||
length = int(arg)
|
||||
password(length, simple)
|
||||
|
||||
elif cmd == 'uuid':
|
||||
gen_uuid()
|
||||
|
||||
elif cmd == 'lorem':
|
||||
words = int(sys.argv[2]) if len(sys.argv) > 2 else 50
|
||||
lorem(words)
|
||||
|
||||
elif cmd == 'hash' and len(sys.argv) > 2:
|
||||
text = ' '.join(sys.argv[2:])
|
||||
hash_text(text)
|
||||
|
||||
elif cmd in ['rand', 'random']:
|
||||
min_v = int(sys.argv[2]) if len(sys.argv) > 2 else 1
|
||||
max_v = int(sys.argv[3]) if len(sys.argv) > 3 else 100
|
||||
random_number(min_v, max_v)
|
||||
|
||||
elif cmd == 'pick' and len(sys.argv) > 2:
|
||||
options = sys.argv[2:]
|
||||
random_choice(options)
|
||||
|
||||
elif cmd == 'slug' and len(sys.argv) > 2:
|
||||
text = ' '.join(sys.argv[2:])
|
||||
slug(text)
|
||||
|
||||
elif cmd in ['time', 'timestamp']:
|
||||
timestamp()
|
||||
|
||||
else:
|
||||
print("Unknown command. Run 'gen' for help.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
2
ws
2
ws
@ -47,6 +47,8 @@ COMMANDS = {
|
||||
'gratitude': ('tools/gratitude.py', 'Gratitude log'),
|
||||
'calc': ('tools/calc.py', 'Calculator and converter'),
|
||||
'timer': ('tools/timer.py', 'Countdown and stopwatch'),
|
||||
'gen': ('tools/gen.py', 'Password, UUID, lorem, etc.'),
|
||||
'fortune': ('tools/fortune.py', 'Random wisdom'),
|
||||
|
||||
# Projects
|
||||
'news': ('projects/news-feed/main.py', 'RSS news reader'),
|
||||
|
||||
Reference in New Issue
Block a user