Commit b6a9ff7d5df6d55ebd2fab0301b0438dc30722ff
1 parent
ed8c0256
Exists in
release
Documentation of Extractor.py
Showing
3 changed files
with
49 additions
and
8 deletions
Show diff stats
core/extractor.py
... | ... | @@ -20,15 +20,16 @@ import pika |
20 | 20 | import PikaManager |
21 | 21 | import pysrt |
22 | 22 | import json |
23 | +import logging #Logging | |
24 | + | |
23 | 25 | from thread import start_new_thread |
24 | 26 | from time import sleep |
25 | 27 | from urllib import urlretrieve |
26 | -import logging #Logging | |
27 | 28 | |
28 | 29 | logger = logging.getLogger('extractor') |
29 | 30 | logger.setLevel(logging.DEBUG) |
30 | 31 | |
31 | -fh = logging.FileHandler('extractor.log') | |
32 | +fh = logging.FileHandler('../log/extractor.log') | |
32 | 33 | fh.setLevel(logging.DEBUG) |
33 | 34 | |
34 | 35 | ch = logging.StreamHandler() |
... | ... | @@ -41,12 +42,26 @@ ch.setFormatter(formatter) |
41 | 42 | logger.addHandler(fh) |
42 | 43 | logger.addHandler(ch) |
43 | 44 | |
44 | -manager = PikaManager.PikaManager('150.165.205.10', "test", "test") | |
45 | +manager = PikaManager.PikaManager("150.165.205.10", "test", "test") | |
45 | 46 | |
46 | 47 | #conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) |
47 | 48 | #conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) |
48 | 49 | |
49 | 50 | def run(ch, method, properties, body): |
51 | + """ | |
52 | + Execute the worker. | |
53 | + | |
54 | + Parameters | |
55 | + ---------- | |
56 | + ch : object | |
57 | + Channel of communication. | |
58 | + method : function | |
59 | + Callback method. | |
60 | + properties : object | |
61 | + Message containing a set of 14 properties. | |
62 | + body : json object | |
63 | + Informations received from queue. | |
64 | + """ | |
50 | 65 | logger.info("Processando a requisição " + properties.correlation_id.encode("utf-8")) |
51 | 66 | # body it's a json that contains subtitle file |
52 | 67 | body = json.loads(body) |
... | ... | @@ -80,10 +95,23 @@ def run(ch, method, properties, body): |
80 | 95 | os.remove(filename) |
81 | 96 | # Send the body to the queue |
82 | 97 | logger.info("Enviando para a fila de extrações") |
83 | - manager.send_to_queue("extractions",body, properties) | |
98 | + manager.send_to_queue("extractions", body, properties) | |
84 | 99 | print ("Sucess") |
85 | 100 | |
86 | 101 | def calculate_ms(time_in): |
102 | + """ | |
103 | + Calculates timestamp in milliseconds. | |
104 | + | |
105 | + Parameters | |
106 | + ---------- | |
107 | + time_in : string | |
108 | + Time in of timestamp. | |
109 | + | |
110 | + Returns | |
111 | + ------- | |
112 | + number | |
113 | + The timestamp in milliseconds. | |
114 | + """ | |
87 | 115 | time = time_in.split(":") |
88 | 116 | time = time[:2] + time[2].split(",") |
89 | 117 | hour = int(time[0]) * 3600000 |
... | ... | @@ -93,6 +121,16 @@ def calculate_ms(time_in): |
93 | 121 | return millisec |
94 | 122 | |
95 | 123 | def keep_alive(conn_send, conn_receive): |
124 | + """ | |
125 | + Keep the connection alive. | |
126 | + | |
127 | + Parameters | |
128 | + ---------- | |
129 | + conn_send : object | |
130 | + Connection of writer. | |
131 | + conn_receive : object | |
132 | + Connection of receiver. | |
133 | + """ | |
96 | 134 | while True: |
97 | 135 | sleep(30) |
98 | 136 | try: |
... | ... | @@ -103,6 +141,7 @@ def keep_alive(conn_send, conn_receive): |
103 | 141 | |
104 | 142 | start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive())) |
105 | 143 | |
144 | +print("Extractor listening...") | |
106 | 145 | while True: |
107 | 146 | try: |
108 | 147 | manager.receive_from_queue("requests", run) | ... | ... |
core/mixer.py
... | ... | @@ -31,7 +31,7 @@ PATH_VIDEO="/home/caiomcg/videos/" |
31 | 31 | logger = logging.getLogger('mixer') |
32 | 32 | logger.setLevel(logging.DEBUG) |
33 | 33 | |
34 | -fh = logging.FileHandler('mixer.log') | |
34 | +fh = logging.FileHandler('../log/mixer.log') | |
35 | 35 | fh.setLevel(logging.DEBUG) |
36 | 36 | |
37 | 37 | ch = logging.StreamHandler() |
... | ... | @@ -47,7 +47,7 @@ logger.addHandler(ch) |
47 | 47 | #conn_send = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) |
48 | 48 | #conn_receive = pika.BlockingConnection(pika.ConnectionParameters(host='localhost',heartbeat_interval=0)) |
49 | 49 | |
50 | -manager = PikaManager.PikaManager('150.165.205.10', "test", "test") | |
50 | +manager = PikaManager.PikaManager("150.165.205.10", "test", "test") | |
51 | 51 | |
52 | 52 | def main_video_height(main_video): |
53 | 53 | """ |
... | ... | @@ -146,7 +146,7 @@ def run(ch, method, properties, body): |
146 | 146 | ch : object |
147 | 147 | Channel of communication. |
148 | 148 | method : function |
149 | - Callback. | |
149 | + Callback method. | |
150 | 150 | properties : object |
151 | 151 | Message containing a set of 14 properties. |
152 | 152 | body : json object |
... | ... | @@ -203,6 +203,7 @@ def run(ch, method, properties, body): |
203 | 203 | # Send the body to the queue |
204 | 204 | logger.info("Enviando para a fila de videos") |
205 | 205 | manager.send_to_queue("videos", body, properties) |
206 | + print ("Success") | |
206 | 207 | |
207 | 208 | # Starts listening |
208 | 209 | print("Mixer listening...") | ... | ... |
core/translator.py
... | ... | @@ -55,7 +55,7 @@ def run(ch, method, properties, body): |
55 | 55 | ch : object |
56 | 56 | Channel of communication. |
57 | 57 | method : function |
58 | - Callback. | |
58 | + Callback method. | |
59 | 59 | properties : object |
60 | 60 | Message containing a set of 14 properties. |
61 | 61 | body : json object |
... | ... | @@ -99,6 +99,7 @@ def keep_alive(conn_send, conn_receive): |
99 | 99 | |
100 | 100 | start_new_thread(keep_alive, (manager.get_conn_send(), manager.get_conn_receive())) |
101 | 101 | |
102 | +print("Translator listening...") | |
102 | 103 | while True: |
103 | 104 | try: |
104 | 105 | manager.receive_from_queue("extractions", run) | ... | ... |