close mongo connection

This commit is contained in:
耿伦伦 2021-12-01 23:44:25 +08:00
parent 481c2f8b6b
commit d61800b755
12 changed files with 21 additions and 3 deletions

13
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": ["https://live.douyin.com/162574996168"]
}
]
}

View File

@ -59,6 +59,8 @@ class Base:
except Exception as e:
print(self.instance.common.method + ' persists error')
print(traceback.format_exc())
finally:
store.close()
def __str__(self):
pass

View File

@ -16,4 +16,4 @@ class RoomUserSeqMessage(Base):
return self.instance.totalUserStr
def __str__(self):
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '【观看人数】' + self.format_content()
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '【观看人数】' + '当前在线:' + str(self.instance.total) + ',历史总计:' + self.format_content()

View File

@ -1,4 +1,3 @@
import time
import concurrent.futures
import queue

View File

@ -15,7 +15,7 @@ from store.mongo import MongoStore
def go(url):
chrome_options = Options()
chrome_options.add_argument('--proxy-server=%s' % config()['webdriver']['proxy'])
# chrome_options.add_argument('--headless')
chrome_options.add_argument('--headless')
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
@ -52,6 +52,7 @@ def go(url):
'admin_user_ids': roomInfo['room']['admin_user_ids'],
'owner': roomInfo['room']['owner']
})
store.close()
wait.until(presence_of_element_located((By.CLASS_NAME, "oSu9Aw19")))

View File

@ -7,6 +7,9 @@ class MongoStore:
self.client = pymongo.MongoClient(config()['mongo']['uri'])
self.db = self.client[config()['mongo']['dbname']]
def close(self):
self.client.close()
def set_collection(self, collection):
self.collection = self.db[collection]