Explorar el Código

Use TCP for irccat

master
Chris Smith hace 5 años
padre
commit
74e7b7d8cf
Se han modificado 2 ficheros con 10 adiciones y 8 borrados
  1. 2
    1
      lineandsinker/services/__init__.py
  2. 8
    7
      lineandsinker/services/irccat.py

+ 2
- 1
lineandsinker/services/__init__.py Ver fichero

21
 
21
 
22
 def irccat_factory():
22
 def irccat_factory():
23
     return IrcCat(
23
     return IrcCat(
24
-        os.environ["LAS_IRCCAT_URL"],
24
+        os.environ["LAS_IRCCAT_HOST"],
25
+        int(os.environ["LAS_IRCCAT_PORT"]),
25
         os.environ["LAS_IRCCAT_CHANNEL"],
26
         os.environ["LAS_IRCCAT_CHANNEL"],
26
     )
27
     )
27
 
28
 

+ 8
- 7
lineandsinker/services/irccat.py Ver fichero

1
-import requests
1
+import socket
2
 
2
 
3
 from .service import Service
3
 from .service import Service
4
 
4
 
5
 
5
 
6
 class IrcCat(Service):
6
 class IrcCat(Service):
7
-    def __init__(self, url, channel):
7
+    def __init__(self, host, port, channel):
8
         super().__init__("irccat")
8
         super().__init__("irccat")
9
-        self._url = url
9
+        self._host = host
10
+        self._port = port
10
         self._channel = channel
11
         self._channel = channel
11
 
12
 
12
     def announce(self, message):
13
     def announce(self, message):
14
+        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
15
+        s.connect((self._host, self._port))
13
         for line in message.split("\n"):
16
         for line in message.split("\n"):
14
-            requests.post(
15
-                self._url,
16
-                f"{self._channel}, {line}",
17
-            )
17
+            s.sendall(bf"{self._channel} {line}\n")
18
+        s.close()

Loading…
Cancelar
Guardar