-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.py
78 lines (63 loc) · 2.09 KB
/
router.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
# this will route the flow of the program to the different modules, manage outputs and so on
import time
import asyncio
import socket
import daemon
import random
import json
from ocr import ocr
from networking import server
from question import Question
from os import listdir
from os.path import isfile, join
from solvers import handler
from colorama import Fore, Back, Style
import result_analysis
def singleFile(filename):
print(f"Analizando imagen {filename}")
tstart = int(round(time.time() * 1000))
myquestion = ocr.getQuestionfromFilename(filename)
coro = handler.answer_question(
myquestion.pregunta, myquestion.respuestas)
try:
myquestion.respuestaPropuesta = asyncio.get_event_loop().run_until_complete(
coro)
except Exception as e:
print(e)
tend = int(round(time.time() * 1000))
myquestion.searchTime = tend-tstart
return myquestion
def allInFolder(path):
print(f"Analizando todas las imagenes en {path}...")
imagelist = [image for image in listdir(path)
if isfile(join(path, image))]
for image in imagelist:
singleFile(join(path, image))
def autonomousMode():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
IP = ""
try:
s.connect(('10.255.255.255', 1))
IP = s.getsockname()[0]
except:
IP = '127.0.0.1'
finally:
s.close()
print("\nconfettibot: modo autonomo\n")
print("Iniciando daemon...")
server.startserver(IP)
def daemonMode():
print("\nconfettibot: modo autonomo\n")
print("Iniciando daemon...")
fstdout = open("pyconfettibot-out.log", "w")
fstderr = open("pyconfettibot-error.log", "w")
with daemon.DaemonContext(stdout=fstdout, stderr=fstderr):
server.startserver('127.0.0.1')
def writeToFile(path):
print("\nconfettibot: modo estadistico\n")
print(f"Analizando todas las imagenes en {path}...")
result_analysis.writeJSONFile(path)
def analyzeJSONFile(path):
print("\nconfettibot: modo estadistico\n")
print(f"Analizando datos en {path}...")
result_analysis.analyzeJSONFile(path)