-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
main.py
34 lines (29 loc) · 849 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
import sys
import black
def check_code_snippet(code_snippet: str):
try:
formatted_code = black.format_str(code_snippet, mode=black.FileMode())
except Exception as e:
return {
'status': 'error',
'error': str(e),
}
if formatted_code.strip() == code_snippet.strip():
return {
'status': 'success',
}
return {
'status': 'updated',
'newCode': formatted_code,
}
def main():
code_snippets_path = sys.argv[1]
if not code_snippets_path:
print("No code snippets path provided")
return
code_snippets = json.load(open(code_snippets_path))
formatted_codes = [check_code_snippet(snippet["code"]) for snippet in code_snippets]
print(json.dumps(formatted_codes))
if __name__ == "__main__":
main()