Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
moonlightwatch committed Aug 21, 2018
0 parents commit ed33592
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

config.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## 不定期更新的密码字典
73 changes: 73 additions & 0 deletions update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# coding=utf-8

import os
import json
import pymongo


class ExportPasswordList(object):
"""
导出密码字典
"""

def __init__(self):
self._config = self._get_config()
self._db_client = self._get_db(self._config)
self.collection = self._get_dbcollection(self._config)
self.passwords = set()

def get_all_passwords(self) -> list:
"""
获取数据
"""
count = self.collection.count()
i = 1
while True:
s = self.collection.find({}).skip(1000*i).limit(1000)
for item in s:
self.passwords.add(item["p"])
print(f"{len(self.passwords)}/{count}")
if s.count() < 1000:
break
i += 1
return self.passwords

def _get_config(self) -> dict:
"""
从配置文件获取配置
"""
json_str = ""
with open(file="config.json", mode="r", encoding="utf-8") as fp:
json_str = fp.read()
return json.loads(s=json_str)

def _get_db(self, config: dict) -> pymongo.mongo_client.MongoClient:
"""
获取数据库客户端实例
"""
return pymongo.mongo_client.MongoClient(
host=config["host"], port=config["port"])

def _get_dbcollection(self, config: dict) -> pymongo.collection.Collection:
"""
获取数据库Collection
"""
up = self._db_client.get_database(config["db"])
up.authenticate(name=config["user"], password=config["pwd"])
return up.get_collection("p")

def close(self):
"""
关闭数据库链接
"""
self._db_client.close()


def main():
export = ExportPasswordList()
export.get_all_passwords()
export.close()


if __name__ == '__main__':
main()

0 comments on commit ed33592

Please sign in to comment.