-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf-paste.py
executable file
·63 lines (55 loc) · 1.83 KB
/
cf-paste.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python3
# --------------------------------------------------------------------------- #
# This script allows you to quickly paste test examples for codeforces problems
# within your source file as JSON object. It is designed to be used alongside
# cf-tool that allows you to quickly test all test cases.
#
# https://github.com/dulex123/competitive-flow
# --------------------------------------------------------------------------- #
import json
import pyperclip
from collections import OrderedDict as oDict
# Our json object that will contain all data about our source code
json_out = oDict()
json_out["name"] = ""
json_out["desc"] = ""
json_out["tags"] = ""
json_out["tests"] = oDict()
# Get content from clipboard
data = pyperclip.paste()
# Arrays for inputs/outputs of test cases
in_array = []
out_array = []
in_temp = ""
out_temp = ""
# Get all inputs/outputs
flag_in = True
flag_out = False
for line in data.splitlines()[1:]:
if line == "Input" or line == "input":
flag_in = True
flag_out = False
out_array.append(out_temp.strip())
out_temp = ""
elif line == "Output" or line == "output":
flag_in = False
flag_out = True
in_array.append(in_temp.strip())
in_temp = ""
elif line == "":
continue
elif flag_in:
in_temp += line.replace('\n', ' ') + ' '
elif flag_out:
out_temp += line.replace('\n', ' ') + ' '
out_array.append(out_temp.strip())
i = 0
for test_in, test_out in zip(in_array, out_array):
i += 1
json_out["tests"]["test" + str(i)] = oDict()
json_out["tests"]["test" + str(i)]["in"] = test_in
json_out["tests"]["test" + str(i)]["out"] = test_out
# Save to clipboard as c++ commented JSON object
clipboard_content = "/*\n" + json.dumps(json_out, indent=4) + "\n*/"
pyperclip.copy(clipboard_content)
pyperclip.paste()