1- import os , sys
1+ import argparse
2+ import os
3+ import sys
4+ from dataclasses import asdict
5+ from enum import StrEnum
6+ from pprint import pprint
7+
28sys .path .insert (0 , os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." )))
39
4- from social_posters .mastodon import PosterMastodon
510from mastodon_manual_test import post_exceed_500_chars_limit_with_adoption_link
11+ from social_posters .mastodon import PosterMastodon
612
7- poster = PosterMastodon .__new__ (PosterMastodon )
8-
9- pet = post_exceed_500_chars_limit_with_adoption_link ()
10- post = poster .format_post (pet )
11-
12- main_caption , replies = poster ._format_caption_thread (post )
13+ """
14+ How to use this to see each stage of the pipeline:
15+ see pet information:
16+ python manual_tests/mastodon_preview.py --stage pet
17+ see post information (platform ready but not mastodon processed):
18+ python manual_tests/mastodon_preview.py --stage post
19+ see full formatting in mastodon:
20+ python manual_tests/mastodon_preview.py --stage debug
21+ see only main thread part of the formatting in mastodon:
22+ python manual_tests/mastodon_preview.py --stage main
23+ see only replies part of the formatting in mastodon:
24+ python manual_tests/mastodon_preview.py --stage replies
25+ see all stages:
26+ python manual_tests/mastodon_preview.py --stage all (or no arg default to all)
27+ """
28+ class PreviewStage (StrEnum ):
29+ PET = "pet"
30+ POST = "post"
31+ DEBUG = "debug"
32+ MAIN = "main"
33+ REPLIES = "replies"
34+ ALL = "all"
1335
14- print ("\n " + "=" * 60 )
15- print ("MAIN POST" )
16- print ("=" * 60 )
17- print (main_caption )
18- print (f"\n Length: { len (main_caption )} " )
1936
20- for i , reply in enumerate ( replies , start = 1 ) :
37+ def print_section ( title : str ) -> None :
2138 print ("\n " + "=" * 60 )
22- print (f"REPLY { i } " )
39+ print (title )
2340 print ("=" * 60 )
24- print (reply )
25- print (f"\n Length: { len (reply )} " )
41+
42+
43+ def parse_args () -> argparse .Namespace :
44+ parser = argparse .ArgumentParser (
45+ description = "Preview each stage of the Mastodon formatting pipeline."
46+ )
47+ parser .add_argument (
48+ "--stage" ,
49+ type = PreviewStage ,
50+ choices = list (PreviewStage ),
51+ default = PreviewStage .ALL ,
52+ help = "Which construction stage to preview." ,
53+ )
54+ return parser .parse_args ()
55+
56+
57+ def should_show (selected : PreviewStage , target : PreviewStage ) -> bool :
58+ return selected in (target , PreviewStage .ALL )
59+
60+
61+ def main () -> None :
62+ args = parse_args ()
63+ stage : PreviewStage = args .stage
64+
65+ poster = PosterMastodon .__new__ (PosterMastodon )
66+
67+ pet = post_exceed_500_chars_limit_with_adoption_link ()
68+ post = poster .format_post (pet )
69+
70+ main_caption , replies , debug = poster ._format_caption_thread_with_trace (post )
71+
72+ if should_show (stage , PreviewStage .PET ):
73+ print_section ("PET" )
74+ pprint (pet )
75+
76+ if should_show (stage , PreviewStage .POST ):
77+ print_section ("POST OBJECT" )
78+ pprint (post )
79+
80+ if should_show (stage , PreviewStage .DEBUG ):
81+ print_section ("DEBUG PIPELINE" )
82+ pprint (asdict (debug ))
83+
84+ if should_show (stage , PreviewStage .MAIN ):
85+ print_section ("MAIN POST" )
86+ print (main_caption )
87+ print (f"\n Length: { len (main_caption )} " )
88+
89+ if should_show (stage , PreviewStage .REPLIES ):
90+ for i , reply in enumerate (replies , start = 1 ):
91+ print_section (f"REPLY { i } " )
92+ print (reply )
93+ print (f"\n Length: { len (reply )} " )
94+
95+
96+ if __name__ == "__main__" :
97+ main ()
0 commit comments