Explorar o código

优化自动创建局域网 clash 节点数据

jack hai 8 meses
pai
achega
c936c55d30
Modificáronse 2 ficheiros con 44 adicións e 0 borrados
  1. 43 0
      models/clash_tools.py
  2. 1 0
      views/view_clash_tools.xml

+ 43 - 0
models/clash_tools.py

@@ -30,6 +30,49 @@ class ClashTools(models.Model):
 
     line_ids = fields.One2many('clash.tools.line', 'clash_tools_id', string='Line')
 
+    def btn_init_data(self):
+        # 一键创建所有局域网中的 clash 连接, 因为懒
+        data_dict = {
+            'web3_01': '192.168.31.201:58001',
+            'web3_02': '192.168.31.201:58002',
+            'web3_03': '192.168.31.201:58003',
+            'web3_04': '192.168.31.201:58004',
+            'web3_05': '192.168.31.201:58005',
+            'web3_06': '192.168.31.201:58006',
+            'web3_07': '192.168.31.201:58007',
+            'web3_08': '192.168.31.201:58008',
+            'web3_09': '192.168.31.201:58009',
+            'web3_10': '192.168.31.201:58010',
+            'depin_01': '192.168.31.201:32001',
+            'depin_02': '192.168.31.201:32002',
+            'depin_03': '192.168.31.201:32003',
+            'depin_04': '192.168.31.201:32004',
+            'depin_05': '192.168.31.201:32005',
+            'depin_06': '192.168.31.201:32006',
+            'depin_07': '192.168.31.201:32007',
+            'depin_08': '192.168.31.201:32008',
+            'depin_09': '192.168.31.201:32009',
+            'depin_10': '192.168.31.201:32010',
+            'depin_11': '192.168.31.201:32011',
+            'depin_12': '192.168.31.201:32012',
+        }
+        all_data_name_list = [i.name for i in self.search([])]
+        print(all_data_name_list)
+        for key, value in data_dict.items():
+            if key in all_data_name_list:
+                continue
+            else:
+                use_type = ''
+                if 'depin' in key:
+                    use_type = 'depin'
+                elif 'web3' in key:
+                    use_type = 'web3'
+                self.create({
+                    'name': key,
+                    'localhost_ip': value,
+                    'use_type': use_type
+                })
+
     def btn_get_all_node(self):
         for rec in self:
             if not rec.localhost_ip:

+ 1 - 0
views/view_clash_tools.xml

@@ -6,6 +6,7 @@
         <field name="arch" type="xml">
             <list string="Clash Tools">
                 <header>
+                    <button name="btn_init_data" type="object" string="Init Data" class="oe_highlight"/>
                     <button name="btn_get_all_node" type="object" string="Get All Proxy" class="oe_highlight"/>
                     <button name="btn_check_all_node" type="object" string="Check All Proxy" class="oe_highlight"/>
                     <button name="btn_select_node" type="object" string="Select Node" class="oe_highlight"/>