Explorar el Código

DNS solver en place, envoie tes photos elias ptn

feature/message_filters
Figg hace 8 meses
padre
commit
183acd4e97
Se han modificado 3 ficheros con 41 adiciones y 3 borrados
  1. 1
    0
      DNS
  2. 36
    0
      million/analyze/dns_solver.py
  3. 4
    3
      million/analyze/message_evaluation.py

+ 1
- 0
DNS Ver fichero

@@ -0,0 +1 @@
1
+https://www.youtube.com/watch?v=mC9yute2k_Q 3000

+ 36
- 0
million/analyze/dns_solver.py Ver fichero

@@ -0,0 +1,36 @@
1
+from typing import Dict
2
+
3
+from pydantic import BaseModel, PrivateAttr
4
+from million.model.message import Message
5
+
6
+_default_file_path = './DNS'
7
+
8
+class DNS_solver(BaseModel):
9
+    file_path:str = _default_file_path
10
+
11
+    _bank: Dict[str, int] | None = PrivateAttr(None)
12
+
13
+    def solve(self, msg: Message) -> int:
14
+        if self._bank == None: 
15
+            self._bank = self.load(_default_file_path)
16
+
17
+        k = self._get_key(msg)
18
+        if k and k in self._bank: return self._bank[k]
19
+
20
+        return None
21
+
22
+    def load(self, file_name: str) -> Dict[str, int]:
23
+        result = {}
24
+        with open(file_name, 'r') as f:
25
+            for line in f:
26
+                a,b = line.split()
27
+                result[a] = int(b)
28
+
29
+        return result
30
+
31
+    def _get_key(self, msg: Message) -> str:
32
+
33
+        # look into msg attributes
34
+        # find uri
35
+        return (msg.share or None) and msg.share.link or \
36
+            (msg.gifs or None) and msg.gifs[0].uri

+ 4
- 3
million/analyze/message_evaluation.py Ver fichero

@@ -1,10 +1,11 @@
1 1
 import re
2 2
 from typing import Dict
3 3
 from million.model.message import Message
4
+import million.analyze.dns_solver as dns
4 5
 
5 6
 
6 7
 _memoization: Dict[Message, int] = {}
7
-
8
+_dns_solver: dns.DNS_solver = dns.DNS_solver()
8 9
 
9 10
 def get(msg: Message) -> int:
10 11
     """
@@ -27,8 +28,8 @@ def reset() -> None:
27 28
 
28 29
 
29 30
 def _compute(msg: Message) -> int:
30
-    # TODO WIP - DNS to resolve audio, gif, pictures with counts
31
-    value = _computeContent(msg) or \
31
+    value = _dns_solver.solve(msg) or \
32
+        _computeContent(msg) or \
32 33
         None
33 34
 
34 35
     _memoization[msg] = value

Loading…
Cancelar
Guardar