diff --git a/database/mongodb.py b/database/mongodb.py new file mode 100644 index 0000000000000000000000000000000000000000..2bc736b4fa467cd00cdf1f55f61af11ecf3ac489 --- /dev/null +++ b/database/mongodb.py @@ -0,0 +1,21 @@ +import pymongo + +# Replace the uri string with your MongoDB deployment's connection string. +conn_str = "mongodb://root:123456@192.168.247.135:27017/?authSource=admin" +# set a 5-second connection timeout +client = pymongo.MongoClient(conn_str, serverSelectionTimeoutMS=5000) +try: + db = client.admin + print(db.name) + collection = db['students'] + student = { + 'id': '201701014', + 'name': 'Jordan', + 'age': 20, + 'gender': 'male' + } + result = collection.insert_one(student) + print(db['students'].info) +except Exception as e: + print("Unable to connect to the server.") + print(f"-{e}") diff --git a/database/mongodb_request.py b/database/mongodb_request.py new file mode 100644 index 0000000000000000000000000000000000000000..15de6a2cbae009e736aba1424beb252963f3fea2 --- /dev/null +++ b/database/mongodb_request.py @@ -0,0 +1,24 @@ +import requests +import pymongo + + +class MongodbDataBase: + conn_str = "mongodb://root:123456@192.168.247.135:27017/?authSource=admin" + + def __init__(self): + self.client = pymongo.MongoClient(self.conn_str, serverSelectionTimeoutMS=5000) + try: + db = client.admin + print(db.name) + collection = db['students'] + student = { + 'id': '201701014', + 'name': 'Jordan', + 'age': 20, + 'gender': 'male' + } + result = collection.insert_one(student) + print(db['students'].info) + except Exception as e: + print("Unable to connect to the server.") + print(f"-{e}") diff --git a/leetcode/matrix_lucky_number.py b/leetcode/matrix_lucky_number.py new file mode 100644 index 0000000000000000000000000000000000000000..75a1eaad7198c0c7751d96ed3db771a8bb62552f --- /dev/null +++ b/leetcode/matrix_lucky_number.py @@ -0,0 +1,9 @@ + +class Solution: + def luck_number(self, matrix: list(list[int])) -> list[int]: + ans = [] + for row in matrix: + for j, x in enumerate(row): + if max(r[j] for r in matrix) <= x <= min(row): + ans.append(x) + return ans \ No newline at end of file diff --git "a/python_note/\347\274\226\347\240\201.py" "b/python_note/\347\274\226\347\240\201.py" new file mode 100644 index 0000000000000000000000000000000000000000..9a85a3d25283ae85e93e6a31efbac32e3eb8b836 --- /dev/null +++ "b/python_note/\347\274\226\347\240\201.py" @@ -0,0 +1,4 @@ +#!/use/bin/python +# coding=utf-8 + +print("你好") \ No newline at end of file