Skip to content

Commit 8dc3276

Browse files
committed
Refactoring for local testing 🛠
1 parent 2c3a0e5 commit 8dc3276

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@
6363
# setup
6464
pipenv install --dev
6565
# testing
66-
pipenv run python codestats_box.py test <gist-id> <github-token> <user> <type>
66+
# only content
67+
pipenv run python codestats_box.py test <codestats-user> <stats-type>
68+
# content and gist update
69+
pipenv run python codestats_box.py test <codestats-user> <stats-type> <gist-id> <github-token>
6770
# example
68-
# pipenv run python codestats_box.py test ce5221fc5f3739d2c81ce7db99f17519 cf9181618bf1618253d17161843f71a2bb161850 aksh recent-xp
71+
# pipenv run python codestats_box.py test aksh recent-xp ce5221fc5f3739d2c81ce7db99f17519 cf9181618bf1618253d17161843f71a2bb161850
6972
```

codestats_box.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

182186
if __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

Comments
 (0)