Browse Source

feat: add create_page

wuwenyi 2 months ago
parent
commit
64a6e04912
3 changed files with 18 additions and 1 deletions
  1. 1 1
      api/__init__.py
  2. 13 0
      api/login.py
  3. 4 0
      browser/__init__.py

+ 1 - 1
api/__init__.py

@@ -40,7 +40,7 @@ def get_idle_account():
         time.sleep(1)
 
 
-def add_phone(account):
+def add_account(account):
     accounts.add(account)
 
 

+ 13 - 0
api/login.py

@@ -10,3 +10,16 @@ import instagram
 
 login_opt = Blueprint('login', __name__)
 
+@login_opt.route('/createPage', methods=["POST"])
+def create_page():
+    """
+    登录接口
+    """
+    request_body = request.json
+    account = request_body.get('account')
+    if not api.contain_browser(account):
+        browser = instagram.InstagramBrowser(account)
+        browser.__init_browser__(playwright=None)
+        browser.close()
+        api.add_account(account)
+    return api.success()

+ 4 - 0
browser/__init__.py

@@ -50,6 +50,10 @@ class BaseBrowser:
         self.browser.add_init_script(path="./stealth.min.js")
         self.page = self.browser.pages[0]
 
+    def close(self):
+        self.browser.close()
+        self.playwright.stop()
+
     @abstractmethod
     def __get_name__(self):
         pass