-
Notifications
You must be signed in to change notification settings - Fork 0
/
evalpy.py
148 lines (116 loc) · 4.02 KB
/
evalpy.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# ===================
# 1. sample txt 를 불러 온다
# sample txt 에는
# 엑셀의 rows 범위를 읽어 오고, 그 범위 만큼 시도한다
# 명령어 뭉치 들이 있다
# 명령어중 command 와 위치 지정에 대한 내용이 있다.
#
#
# 1
# 1
#
# ===================
import openpyxl
from openpyxl.utils import coordinate_from_string, column_index_from_string
# xy = coordinate_from_string('A4') # returns ('A',4)
# col = column_index_from_string(xy[0]) # returns 1
# row = xy[1]
filename = 'sample.txt'
class DoReMi():
def __init__(self, filename=filename):
with open(filename, 'r+') as f:
self.func_list = f.readlines()
print('range는 ' + self.func_list[0].strip('\n')+ ' 입니다.')
self.range = self.func_list[2].strip('\n')
self.func_list = self.func_list[3:]
input_range = self.range # 'a1:d5'
_ranges = input_range.split(':')
_ranges_start = _ranges[0]
_ranges_end = _ranges[1]
start_xy = coordinate_from_string(_ranges_start)
start_col = column_index_from_string(start_xy[0]) # returns 1
start_row = start_xy[1]
end_xy = coordinate_from_string(_ranges_end)
end_col = column_index_from_string(end_xy[0]) # returns 1
end_row = end_xy[1]
self.start_col = start_col
self.start_row = start_row
self.end_col = end_col
self.end_row = end_row
self.alist = [ start_col, start_row, end_col, end_row]
# print('TODO : 엑셀에서 범위를 읽어 와야 합니다.')
print(self.range)
print('range 를 숫자로 하면')
print(self.alist)
def print_f1_lst(self):
print(f1_lst)
def lst(self):
print(self.func_list)
def do(self):
print("Do")
def re(self):
print("Re")
def mi(self):
print("Mi")
print("구현해야 할 함수는 \n"
"enter, spacebar, type, ctrl_v")
def click(self, pos_x, pos_y):
print('I clicked!,'+pos_x+pos_y)
def ctrl_v(self, pos):
print(pos.value)
def enter(self, times=1):
for i in range(times):
print('Hit enterKey!')
i+=1
def spacebar(self, times=1):
for i in range(times):
print('Hit spacebar!')
i+=1
def sleep(self, times=1):
for i in range(times):
print('Sleep')
i+=1
def movetoright(self, times=1):
for i in range(times):
print('Hit move to right!')
i+=1
def movetoleft(self, times=1):
for i in range(times):
print('Hit move to left!')
i+=1
def movetoup(self, times=1):
for i in range(times):
print('Hit move to up!')
i+=1
def movetodown(self, times=1):
for i in range(times):
print('Hit move to down')
i+=1
def type(self, t):
print(t+'를 입력하셨습니다.')
def run_func(self):
for func in self.func_list:
func = func.strip("\n").lower()
if func.startswith('{{') & func.endswith('}}'):
func = func[2:-2]
try:
exec('self.' + func)
# exec('self.'+func + '()')
except:
print(func+' 함수는 없습니다.')
elif func.startswith('[[') & func.endswith(']]'):
r = 1
pos = func[2:-2]
try:
exec('self.ctrl_v(' + pos + str(r) + ')') # self.ctrl_v(pos+r)
print('copy_and_paste')
except:
print('붙여넣기 에러 발생')
elif func.startswith('((') & func.endswith('))'):
try:
print('excel column is ..')
except:
print('exception!')
if __name__ == '__main__':
song = DoReMi()
song.run_func()