plantmap-sv 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import 'tsx';
4
+
3
5
  const { runCli } = await import('../src/lib/cli/index.ts');
4
6
 
5
7
  await runCli(process.argv.slice(2));
package/docs/CHANGELOG.md CHANGED
@@ -15,6 +15,14 @@ The format is (read: strives to be) based on [Keep a Changelog](https://keepacha
15
15
 
16
16
  ---
17
17
 
18
+ ## [0.0.11] – 2026-11-30
19
+
20
+ ### Changed:
21
+
22
+ - Use tsx for bin entry. Move tsx to deps.
23
+
24
+ ---
25
+
18
26
  ## [0.0.10] – 2026-11-30
19
27
 
20
28
  ### Changed:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "plantmap-sv",
3
3
  "private": false,
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
5
5
  "license": "ISC",
6
6
  "repository": {
7
7
  "type": "git",
@@ -52,7 +52,6 @@
52
52
  "svelte": "^5.57.2",
53
53
  "svelte-check": "^4.7.5",
54
54
  "tailwindcss": "^4.3.0",
55
- "tsx": "^4.23.15",
56
55
  "typescript": "^6.0.3",
57
56
  "typescript-eslint": "^8.60.1",
58
57
  "vite": "^8.0.16",
@@ -69,6 +68,7 @@
69
68
  "memphis-settings": "^0.0.10",
70
69
  "nodemailer": "^10.3.1",
71
70
  "proj4": "^2.22.0",
71
+ "tsx": "^4.23.15",
72
72
  "three": "^0.186.1",
73
73
  "three-geo": "^1.4.5",
74
74
  "zod": "^4.6.5"
Binary file
Binary file
@@ -16,7 +16,7 @@ const ReportSchema = z.object({
16
16
  z
17
17
  .object({
18
18
  tags: z.array(z.string().min(1)).optional(),
19
- tagsFiles: z.array(z.string().min(1)).min(1).optional(),
19
+ tagsFiles: z.array(z.string().min(1)).optional(),
20
20
  days: z.number().positive().optional(),
21
21
  formats: z.array(z.enum(SUPPORTED_DOWNLOAD_FORMATS)).min(1).optional(),
22
22
  secondsBetweenPoints: z.number().int().positive().optional()
@@ -34,7 +34,7 @@ const ReportSchema = z.object({
34
34
  const DEFAULT_REPORT_CONFIG: ReportInputJson = {
35
35
  name: 'Weekly Default Report, Name',
36
36
 
37
- recipients: ['testA@example.comv', 'testB@example.com'],
37
+ recipients: ['testA@example.com', 'testB@example.com'],
38
38
 
39
39
  subject: 'Weekly Default Report, Subject',
40
40
 
@@ -1,188 +0,0 @@
1
-
2
- #!/usr/bin/env python3
3
-
4
- import os
5
- import sys
6
- import subprocess
7
- from pathlib import Path
8
- from datetime import datetime, timezone
9
-
10
-
11
- # --------------------------------------------------
12
- # Configuration
13
- # --------------------------------------------------
14
-
15
- REPO_DIR = Path(__file__).resolve().parent.parent
16
-
17
- APP_DIR = Path.home() / ".plantmap-sv"
18
- EXPORT_DIR = APP_DIR / "export"
19
-
20
- QUERY_FILE = REPO_DIR / "queries" / "presson-daily-tags.txt"
21
-
22
- FORMATS = ("csv", "json", "svg")
23
- INTERVAL_SECONDS = "900"
24
- EMAIL_LIST_KEY = "list-3"
25
-
26
- # --------------------------------------------------
27
- # Command execution
28
- # --------------------------------------------------
29
-
30
- def run_command(args: list[str]) -> str:
31
- """Execute a command and return stdout."""
32
-
33
- print(f"\n$ {' '.join(map(str, args))}")
34
-
35
- if os.name == "nt":
36
- # Windows requires shell handling for npx.cmd.
37
- command = subprocess.list2cmdline(
38
- [str(arg) for arg in args]
39
- )
40
-
41
- result = subprocess.run(
42
- command,
43
- shell=True,
44
- cwd=REPO_DIR,
45
- text=True,
46
- capture_output=True,
47
- )
48
- else:
49
- result = subprocess.run(
50
- [str(arg) for arg in args],
51
- cwd=REPO_DIR,
52
- text=True,
53
- capture_output=True,
54
- )
55
-
56
- if result.stdout:
57
- print(result.stdout, end="")
58
-
59
- if result.stderr:
60
- print(result.stderr, end="", file=sys.stderr)
61
-
62
- if result.returncode != 0:
63
- raise RuntimeError(
64
- f"Command failed with exit code {result.returncode}"
65
- )
66
-
67
- return result.stdout.strip()
68
-
69
-
70
- # --------------------------------------------------
71
- # Main workflow
72
- # --------------------------------------------------
73
-
74
- def main():
75
-
76
- EXPORT_DIR.mkdir(parents=True, exist_ok=True)
77
-
78
- if not QUERY_FILE.is_file():
79
- raise FileNotFoundError(
80
- f"Query file not found: {QUERY_FILE}"
81
- )
82
-
83
- # Retrieve recipients from the settings vault.
84
- print("Retrieving email recipients...")
85
-
86
- email_list = run_command([
87
- "npx",
88
- "memphis-settings",
89
- "--app-dir", str(APP_DIR),
90
- "config", "get",
91
- "email-recipient", EMAIL_LIST_KEY,
92
- ])
93
-
94
- if not email_list:
95
- raise RuntimeError("No email recipients configured.")
96
-
97
- # Snapshot existing exports.
98
- before = {
99
- path: path.stat().st_mtime_ns
100
- for path in EXPORT_DIR.iterdir()
101
- if path.is_file()
102
- }
103
-
104
- started = datetime.now(timezone.utc).timestamp_ns() \
105
- if hasattr(datetime.now(timezone.utc), "timestamp_ns") \
106
- else int(datetime.now(timezone.utc).timestamp() * 1_000_000_000)
107
-
108
- # Download telemetry.
109
- print("\nDownloading Presson telemetry...")
110
-
111
- run_command([
112
- "npx",
113
- "plantmap-sv",
114
- "download",
115
- str(QUERY_FILE),
116
- "--days", "1",
117
- "--format", "csv",
118
- "--format", "json",
119
- "--format", "svg",
120
- "-o", str(EXPORT_DIR),
121
- "-sec", INTERVAL_SECONDS,
122
- ])
123
-
124
- # Collect files generated or updated by this run.
125
- attachments = []
126
-
127
- for path in sorted(EXPORT_DIR.iterdir()):
128
-
129
- if not path.is_file():
130
- continue
131
-
132
- if path.suffix.lower() not in FORMATS:
133
- continue
134
-
135
- previous_mtime = before.get(path)
136
-
137
- if previous_mtime is None or path.stat().st_mtime_ns >= started:
138
- if path.stat().st_size == 0:
139
- raise RuntimeError(
140
- f"Empty attachment: {path}"
141
- )
142
-
143
- attachments.append(path)
144
-
145
- if not attachments:
146
- raise RuntimeError("No export attachments were generated.")
147
-
148
- print("\nAttachments:")
149
-
150
- for path in attachments:
151
- print(f" {path}")
152
-
153
- # Send email.
154
- print("\nSending Presson daily report...")
155
-
156
- email_args = [
157
- "npx",
158
- "plantmap-sv",
159
- "email",
160
- "--to", email_list,
161
- "--subject", "Daily Presson Report",
162
- "--body",
163
- (
164
- "Attached is the daily Presson test data report "
165
- "in 15-minute increments. Open the SVG image file "
166
- "in your browser to view the graph. This report "
167
- "was generated using PlantMap-SV automated "
168
- "reporting tools."
169
- ),
170
- ]
171
-
172
- for path in attachments:
173
- email_args.extend([
174
- "--attachment",
175
- str(path),
176
- ])
177
-
178
- run_command(email_args)
179
-
180
- print("\nPresson daily report sent successfully.")
181
-
182
-
183
- if __name__ == "__main__":
184
- try:
185
- main()
186
- except (RuntimeError, FileNotFoundError, OSError) as exc:
187
- print(f"\nERROR: {exc}", file=sys.stderr)
188
- sys.exit(1)
package/pyproject.toml DELETED
@@ -1,16 +0,0 @@
1
- [project]
2
- name = "plantmap-sv"
3
- description = "Python support for plantmap-sv"
4
- dynamic = ["version"]
5
- readme = "README.md"
6
- requires-python = ">=3.11"
7
- dependencies = [
8
- "dworshak-secret>=1.3.6",
9
- ]
10
-
11
- [project.optional-dependencies]
12
- crypto = [
13
- "cryptography>=46.0.3",
14
- "dworshak-secret[crypto]>=1.3.6",
15
- "dworshak-prompt[crypto]",
16
- ]
@@ -1,158 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Send report attachments through Gmail SMTP."""
3
-
4
- import argparse
5
- import mimetypes
6
- import smtplib
7
- import ssl
8
- import sys
9
- from email.message import EmailMessage
10
- from pathlib import Path
11
-
12
- from dworshak_secret import DworshakSecret
13
-
14
-
15
- # Configure these to match the service/item names in your vault.
16
- VAULT_SERVICE = "email"
17
- VAULT_SENDER_ADDRESS_ITEM = "send-address"
18
- VAULT_PASSWORD_ITEM = "send-password"
19
- CONFIG_SERVICE = "email"
20
- CONFIG_SMTP_HOST_ITEM = "smpt-host"
21
- CONFIG_SMTP_PORT_ITEM = "smpt-port"
22
- CONFIG_SMTP_SECURITY_ITEM = "smpt-security"
23
-
24
- # Recipient and sender can be supplied on the command line.
25
- # Alternatively, make them configuration values for your environment.
26
-
27
-
28
- def main():
29
- parser = argparse.ArgumentParser(
30
- description="Send report attachments through Gmail."
31
- )
32
- parser.add_argument(
33
- "--attachment",
34
- action="append",
35
- required=True,
36
- help="File to attach; repeat this option for multiple files.",
37
- )
38
- #parser.add_argument("--from", dest="sender", required=True)
39
- parser.add_argument("--to", dest="recipient", required=True)
40
- parser.add_argument("--subject", default="Automated report")
41
- parser.add_argument(
42
- "--body",
43
- default="Please find the requested reports attached.",
44
- )
45
- args = parser.parse_args()
46
- return args
47
-
48
- # ---
49
-
50
- def resolve_attachments(paths: list[str]) -> list[Path]:
51
- resolved = []
52
-
53
- for raw_path in paths:
54
- path = Path(raw_path).expanduser().resolve(strict=True)
55
-
56
- if not path.is_file():
57
- raise ValueError(f"Attachment is not a file: {path}")
58
-
59
- if path.stat().st_size == 0:
60
- raise ValueError(f"Attachment is empty: {path}")
61
-
62
- resolved.append(path)
63
-
64
- return resolved
65
-
66
-
67
- def add_attachments(
68
- message: EmailMessage,
69
- paths: list[str],
70
- ) -> None:
71
- for path in resolve_attachments(paths):
72
- message.add_attachment(
73
- path.read_bytes(),
74
- maintype="application",
75
- subtype="octet-stream",
76
- filename=path.name,
77
- )
78
-
79
- # ---
80
-
81
- def send_email_with_attachment(
82
- attachments:list[str],
83
- recipient:str,
84
- subject:str,
85
- body:str
86
- )->None:
87
-
88
-
89
- # Retrieve credentials from the local Dworshak vault.
90
- vault = DworshakSecret()
91
- sender_address = vault.get(VAULT_SERVICE, VAULT_SENDER_ADDRESS_ITEM, fail=True)
92
- password = vault.get(VAULT_SERVICE, VAULT_PASSWORD_ITEM, fail=True)
93
- config = DworshakSecret()
94
- smtp_host=config.get(CONFIG_SERVICE, CONFIG_SMTP_HOST_ITEM, default = "smtp.gmail.com")
95
- smtp_port=config.get(CONFIG_SERVICE, CONFIG_SMTP_PORT_ITEM, default = "587")
96
- smtp_security=config.get(CONFIG_SERVICE, CONFIG_SMTP_SECURITY_ITEM, default = "starttls")
97
-
98
- if not sender_address or not password:
99
- raise RuntimeError("Gmail SMTP credentials are missing from the vault.")
100
-
101
- # Build the email.
102
- message = EmailMessage()
103
- message["From"] = sender_address # sender
104
- message["To"] = recipient
105
- message["Subject"] = subject
106
- message.set_content(body)
107
-
108
- attachments = resolve_attachments(attachments)
109
- #add_attachments(message, attachments)
110
-
111
- for path in attachments:
112
- content_type, _ = mimetypes.guess_type(path.name)
113
- if content_type:
114
- maintype, subtype = content_type.split("/", 1)
115
- else:
116
- maintype, subtype = "application", "octet-stream"
117
-
118
- message.add_attachment(
119
- path.read_bytes(),
120
- maintype=maintype,
121
- subtype=subtype,
122
- filename=path.name,
123
- )
124
-
125
- # Send via Gmail using implicit TLS.
126
- context = ssl.create_default_context()
127
-
128
- with smtplib.SMTP(
129
- smtp_host,
130
- smtp_port,
131
- timeout=30,
132
- ) as smtp:
133
- smtp.ehlo()
134
- # if smtp_security == "starttls":
135
- smtp.starttls(context=context)
136
- #else:
137
- #
138
- smtp.ehlo()
139
- smtp.login(sender_address, password)
140
- smtp.send_message(message)
141
-
142
- print(f"Email sent successfully to {recipient}")
143
-
144
-
145
- if __name__ == "__main__":
146
- try:
147
- args = main()
148
- send_email_with_attachment(
149
- attachments = args.attachment,
150
- #sender = args.sender,
151
- recipient = args.recipient,
152
- subject = args.subject,
153
- body = args.body
154
- )
155
-
156
- except Exception as exc:
157
- print(f"Email failed: {exc}", file=sys.stderr)
158
- sys.exit(1)