@@ -157,13 +157,7 @@ def update_gist(title: str, content: str) -> bool:
157157 print (f"{ title } \n { content } " )
158158
159159
160- def main ():
161-
162- if not validate_and_init ():
163- raise RuntimeError (
164- "Validations failed! See the messages above for more information"
165- )
166-
160+ def get_content () -> str :
167161 code_stats_user_name = os .environ [ENV_VAR_CODE_STATS_USERNAME ]
168162 code_stats_response = get_code_stats_response (code_stats_user_name )
169163
@@ -175,20 +169,38 @@ def main():
175169 get_adjusted_line (title_and_value )
176170 for title_and_value in [total_xp_line , * language_xp_lines ]
177171 ]
178- content = "\n " .join (lines )
172+ return "\n " .join (lines )
173+
174+
175+ def main ():
176+
177+ if not validate_and_init ():
178+ raise RuntimeError (
179+ "Validations failed! See the messages above for more information"
180+ )
181+
182+ content = get_content ()
179183 update_gist (GIST_TITLE , content )
180184
181185
182186if __name__ == "__main__" :
183187 import time
184188
185189 s = time .perf_counter ()
186- # test with python codestats_box.py test <gist> <github-token> <user> <type>
190+ # test with
191+ # python codestats_box.py test <codestats-user> <stats-type>
192+ # to only print content. To also test gist update, use:
193+ # python codestats_box.py test <codestats-user> <stats-type> <gist-id> <github-token>
187194 if len (sys .argv ) > 1 :
188- os .environ [ENV_VAR_GIST_ID ] = sys .argv [2 ]
189- os .environ [ENV_VAR_GITHUB_TOKEN ] = sys .argv [3 ]
190- os .environ [ENV_VAR_CODE_STATS_USERNAME ] = sys .argv [4 ]
191- os .environ [ENV_VAR_STATS_TYPE ] = sys .argv [5 ]
192- main ()
195+ os .environ [ENV_VAR_CODE_STATS_USERNAME ] = sys .argv [2 ]
196+ os .environ [ENV_VAR_STATS_TYPE ] = sys .argv [3 ]
197+ if len (sys .argv ) > 4 :
198+ os .environ [ENV_VAR_GIST_ID ] = sys .argv [4 ]
199+ os .environ [ENV_VAR_GITHUB_TOKEN ] = sys .argv [5 ]
200+ main ()
201+ else :
202+ print (get_content ())
203+ else :
204+ main ()
193205 elapsed = time .perf_counter () - s
194206 print (f"{ __file__ } executed in { elapsed :0.2f} seconds." )
0 commit comments