Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ Session.vim
.sudo_as_admin_successful
.noseids
site/
.venv
76 changes: 76 additions & 0 deletions examples/.tomeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

# This file is used to ignore files when doing a tome install.

# Python

.*
__pycache__
*pyc


# macOS

# General
.DS_Store
.AppleDouble
.LSOverride

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
desktop.ini
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# Linux

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

.tome_venv
9 changes: 9 additions & 0 deletions examples/network/tome_ping.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off
REM tome_description: Script to ping an IP address or URL. Arguments: <IP or URL>.

IF "%~1"=="" (
echo Usage: %0 ^<IP or URL^>
exit /b 1
)

ping -n 4 %1
9 changes: 9 additions & 0 deletions examples/network/tome_ping.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# tome_description: Script to ping an IP address or URL. Arguments: <IP or URL>.

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <IP or URL>"
exit 1
fi

ping -c 4 "$1"
9 changes: 9 additions & 0 deletions examples/network/tome_traceroute.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off
REM tome_description: Script to perform a traceroute to an IP address or URL. Arguments: <IP or URL>.

IF "%~1"=="" (
echo Usage: %0 ^<IP or URL^>
exit /b 1
)

tracert %1
9 changes: 9 additions & 0 deletions examples/network/tome_traceroute.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# tome_description: Script to perform a traceroute to an IP address or URL. Arguments: <IP or URL>.

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <IP or URL>"
exit 1
fi

traceroute "$1"
6 changes: 6 additions & 0 deletions examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tweepy
psutil
yfinance
cryptography
requests
yahooquery
41 changes: 41 additions & 0 deletions examples/system/monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import time

from tome.command import tome_command
from tome.api.output import TomeOutput


@tome_command()
def monitor(tome_api, parser, *args):
"""Monitor system usage including CPU, memory, and disk."""
parser.add_argument("--cpu", action="store_true", help="Monitor CPU usage in real-time")
parser.add_argument("--memory", action="store_true", help="Monitor memory usage in real-time")
parser.add_argument("--disk", action="store_true", help="Display disk usage")
args = parser.parse_args(*args)

import psutil

tome_output = TomeOutput()

if not any([args.cpu, args.memory, args.disk]):
# Default to all if no specific option is provided
args.cpu = args.memory = args.disk = True

if args.disk:
disk_usage = psutil.disk_usage("/")
tome_output.info(f"Disk Usage: {disk_usage.percent}% used")
tome_output.info(f"Total: {disk_usage.total / (1024**3):.2f} GB")
tome_output.info(f"Used: {disk_usage.used / (1024**3):.2f} GB")
tome_output.info(f"Free: {disk_usage.free / (1024**3):.2f} GB")

if args.cpu:
cpu_usage = psutil.cpu_percent(interval=1)
tome_output.info(f"CPU Usage: {cpu_usage}%")

if args.memory:
memory_info = psutil.virtual_memory()
tome_output.info(f"Memory Usage: {memory_info.percent}%")
tome_output.info(f"Total: {memory_info.total / (1024**3):.2f} GB")
tome_output.info(f"Used: {memory_info.used / (1024**3):.2f} GB")
tome_output.info(f"Available: {memory_info.available / (1024**3):.2f} GB")
tome_output.info(f"Free: {memory_info.free / (1024**3):.2f} GB")
78 changes: 78 additions & 0 deletions examples/todo/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import os
from tome.command import tome_command
from tome.api.output import TomeOutput


@tome_command()
def tasks(tome_api, parser, *args):
"""Manage your to-do list tasks."""


@tome_command(parent=tasks)
def add(tome_api, parser, *args):
"""Add a new task to the to-do list."""
parser.add_argument("task", help="The task to add to the to-do list.")
args = parser.parse_args(*args)

store_path = tome_api.store.folder
tasks_file = os.path.join(store_path, "tasks.txt")

# Create the store directory if it does not exist
os.makedirs(store_path, exist_ok=True)

# Append the new task to the tasks file
with open(tasks_file, "a") as file:
file.write(args.task + "\n")

tome_output = TomeOutput()
tome_output.info(f"Task added: {args.task}")


@tome_command(parent=tasks)
def remove(tome_api, parser, *args):
"""Remove a task from the to-do list."""
parser.add_argument("task_number", type=int, help="The number of the task to remove.")
args = parser.parse_args(*args)

store_path = tome_api.store.folder
tasks_file = os.path.join(store_path, "tasks.txt")

tome_output = TomeOutput()

if not os.path.exists(tasks_file):
tome_output.error("No tasks found.")
return

with open(tasks_file, "r") as file:
tasks = file.readlines()

if 0 < args.task_number <= len(tasks):
removed_task = tasks.pop(args.task_number - 1)
with open(tasks_file, "w") as file:
file.writelines(tasks)
tome_output.info(f"Removed task: {removed_task.strip()}")
else:
tome_output.error("Invalid task number.")


@tome_command(parent=tasks)
def list(tome_api, parser, *args):
"""List all tasks in the to-do list."""
store_path = tome_api.store.folder
tasks_file = os.path.join(store_path, "tasks.txt")

tome_output = TomeOutput()

if not os.path.exists(tasks_file):
tome_output.info("No tasks found.")
return

with open(tasks_file, "r") as file:
tasks = file.readlines()

if tasks:
tome_output.info("To-Do List:")
for i, task in enumerate(tasks, start=1):
tome_output.info(f"{i}. {task.strip()}")
else:
tome_output.info("No tasks found.")
77 changes: 77 additions & 0 deletions examples/weather/weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os
from tome.command import tome_command
from tome.api.output import TomeOutput
from tome.errors import TomeException


def check_api_key():
API_KEY = os.getenv("OPENWEATHER_API_KEY")

if not API_KEY:
raise TomeException(
"No API key found for OpenWeatherMap. Please set the OPENWEATHER_API_KEY environment variable."
)


@tome_command()
def current(tome_api, parser, *args):
"""Get the current weather for a specific city."""
parser.add_argument("city", help="The city to get the current weather for.")
args = parser.parse_args(*args)

check_api_key()

import requests

tome_output = TomeOutput()

try:
response = requests.get(
f"http://api.openweathermap.org/data/2.5/weather?q={args.city}&appid={API_KEY}&units=metric"
)
response.raise_for_status()
data = response.json()
weather_desc = data["weather"][0]["description"]
temp = data["main"]["temp"]
tome_output.info(f"Current weather in {args.city}: {weather_desc}, {temp}°C")
except requests.exceptions.RequestException as e:
tome_output.error(f"Error fetching weather data: {str(e)}")


@tome_command()
def forecast(tome_api, parser, *args):
"""Get the weather forecast for the next few days in a specific city."""
parser.add_argument("city", help="The city to get the weather forecast for.")
parser.add_argument(
"--days",
type=int,
default=3,
help="Number of days to get the forecast for (max 7).",
)
args = parser.parse_args(*args)

import requests

check_api_key()

tome_output = TomeOutput()

if args.days < 1 or args.days > 7:
tome_output.error("Number of days must be between 1 and 7.")
return

try:
response = requests.get(
f"http://api.openweathermap.org/data/2.5/forecast/daily?q={args.city}&cnt={args.days}&appid={API_KEY}&units=metric"
)
response.raise_for_status()
data = response.json()
tome_output.info(f"Weather forecast for {args.city}:")
for day in data["list"]:
date = day["dt"]
weather_desc = day["weather"][0]["description"]
temp_day = day["temp"]["day"]
temp_night = day["temp"]["night"]
tome_output.info(f"{date}: {weather_desc}, Day: {temp_day}°C, Night: {temp_night}°C")
except requests.exceptions.RequestException as e:
tome_output.error(f"Error fetching weather data: {str(e)}")
43 changes: 43 additions & 0 deletions examples/x/post_tweet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
from tome.command import tome_command
from tome.api.output import TomeOutput


@tome_command()
def tweet(tome_api, parser, *args):
"""
Post a tweet on X (formerly Twitter).
"""
parser.add_argument("message", help="The message to tweet")
parser.add_argument("--image", help="Path to an image to attach to the tweet")
args = parser.parse_args(*args)

import tweepy

# Twitter API credentials (replace with your actual credentials)
api_key = os.getenv("TWITTER_API_KEY")
api_secret_key = os.getenv("TWITTER_API_SECRET_KEY")
access_token = os.getenv("TWITTER_ACCESS_TOKEN")
access_token_secret = os.getenv("TWITTER_ACCESS_TOKEN_SECRET")

if not all([api_key, api_secret_key, access_token, access_token_secret]):
tome_output = TomeOutput()
tome_output.error("Twitter API credentials are not set in environment variables.")
return

# Authenticate to Twitter
auth = tweepy.OAuthHandler(api_key, api_secret_key)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

# Post the tweet
try:
if args.image:
api.update_with_media(args.image, status=args.message)
tome_output.info(f"Tweet posted with image: {args.image}")
else:
api.update_status(status=args.message)
tome_output.info("Tweet posted successfully")
except tweepy.TweepError as e:
tome_output = TomeOutput()
tome_output.error(f"Failed to post tweet: {e.reason}")
Loading
Loading