Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

Commit bcae768

Browse files
committed
feat: project page
1 parent b8fdcdb commit bcae768

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

scratch_cli/__main__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ def main():
4949
config.add_subparsers(dest="config_command").add_parser("edit", help="Edit your scli config")
5050

5151
parser.add_argument("-U", "--user", dest="username",
52-
help="Get user by username")
52+
help="Get user by name")
53+
54+
parser.add_argument("-P", "--project", type=int, dest="project_id",
55+
help="Get project by id")
5356

5457
args = parser.parse_args(namespace=_Args())
5558

@@ -83,6 +86,9 @@ def do_cmd(parser: argparse.ArgumentParser, args: _Args) -> None:
8386
if args.username:
8487
cmd.find(user=args.username)
8588
return
89+
if args.project_id:
90+
cmd.find(project=args.project_id)
91+
return
8692

8793
parser.print_help()
8894

scratch_cli/_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class Args(argparse.Namespace):
55
command: Literal['login', 'group', 'groups', 'ungroup', 'profile', 'find', 'config', None]
66
username: Optional[str]
7+
project_id: Optional[int]
78

89
# find
910
offset: int

scratch_cli/assets/project_page.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# {title} by {author}
2+
3+
## #{id} (https://scratch.mit.edu/projects/{id}/)
4+
5+
### Instructions
6+
7+
{instructions}
8+
9+
### Notes and credits
10+
11+
{notes}
12+
13+
| | | | | |
14+
|---------------|---------------|----|-------------------|-----------------------|
15+
| 👁 Views | {views} | \| | Commenting status | `{commenting_status}` |
16+
| ♥ Loves | {loves} | \| | Last modified | {last_modified} |
17+
| ★ Favorites | {faves} | \| | Created | {created} |
18+
| ꩜ Remix count | {remix_count} | \| | (Remix) Parent ID | {remix_parent} |
19+
20+

scratch_cli/cmd/find.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def find(*,
3535
offset: int = 0,
3636
limit: int = 10,
3737
user: Optional[str] = None,
38+
project: Optional[int] = None,
3839
mode: Optional[str] = None, ):
3940
if user:
4041
user: sa.User = context.session.connect_user(user)
@@ -70,6 +71,15 @@ def find(*,
7071

7172
return
7273

74+
if project:
75+
project: sa.Project = context.session.connect_project(project)
76+
77+
match mode:
78+
case "page" | None:
79+
rfmt.print_md(safmt.project_page(project))
80+
81+
return
82+
7383
# assume we are in session mode
7484
find_in_session(
7585
offset=offset,

scratch_cli/safmt.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ def _handle_configurable_markdownable(raw: str, content: Optional[str], replace:
5353
return f'{raw}{splitter}{content}'
5454
return raw
5555

56+
def project_page(self: sa.Project):
57+
# todo: allow for project-specific scli config
58+
59+
return rfmt.md_fp(
60+
"project_page.md",
61+
title=rfmt.escape(self.title),
62+
author=self.author_name if hasattr(self, "author_name") else None,
63+
id=self.id,
64+
instructions=rfmt.quote(_handle_configurable_markdownable(rfmt.escape(self.instructions), "", False)),
65+
notes=rfmt.quote(_handle_configurable_markdownable(rfmt.escape(self.notes), "", False)),
66+
views=self.views,
67+
loves=self.loves,
68+
faves=self.favorites,
69+
remix_count=self.remix_count,
70+
created=self.created,
71+
last_modified=self.last_modified,
72+
commenting_status="on" if self.comments_allowed else "off",
73+
remix_parent=self.remix_parent
74+
)
5675

5776
def user_profile(self: sa.User):
5877
config = scli_config(self)

0 commit comments

Comments
 (0)