-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisual_basic_math.py
More file actions
49 lines (32 loc) · 1.09 KB
/
Copy pathvisual_basic_math.py
File metadata and controls
49 lines (32 loc) · 1.09 KB
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
# This challenge is WIP
# This script requires tesseract to be installed on your system (https://tesseract-ocr.github.io/tessdoc/Installation.html#installation)
from support import hackattic, download_file
import pytesseract
def read_and_calculate(image_path):
operations = pytesseract.image_to_string(image_path, config='--psm 6')
result = 0
for operation in operations.splitlines():
operation = operation.replace(' ', '').strip()
symbol = operation[0]
number = int(operation[1:])
if symbol == '+':
result += number
elif symbol == '-':
result -= number
elif symbol == 'x':
result *= number
elif symbol == '÷':
result //= number
return result
def run():
problem = hackattic.Problem('visual_basic_math')
data = problem.fetch()
image_path = download_file(data['image_url'], '.png')
print(image_path)
solution = {
'result': read_and_calculate(image_path)
}
print(solution)
# print(problem.solve(solution))
if __name__ == '__main__':
run()