You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
import pymongo
|
|
from datetime import datetime
|
|
from config import MONGODB_URL, MONGODB_USERNAME, MONGODB_PASSWORD, MONGODB_DATABASE
|
|
from utils import get_password_hash
|
|
|
|
client = pymongo.MongoClient(MONGODB_URL, username=MONGODB_USERNAME, password=MONGODB_PASSWORD)
|
|
db = client[MONGODB_DATABASE]
|
|
|
|
def populate_data():
|
|
users_collection = db["users"]
|
|
pins_collection = db["pins"]
|
|
|
|
user1_id = users_collection.insert_one({
|
|
"username": "string",
|
|
"password": get_password_hash("string")
|
|
}).inserted_id
|
|
|
|
user2_id = users_collection.insert_one({
|
|
"username": "test",
|
|
"password": get_password_hash("test")
|
|
}).inserted_id
|
|
|
|
pins_collection.insert_many([
|
|
{
|
|
"title": f"Tour Eiffel",
|
|
"description": "Description A",
|
|
"location": [48.858296, 2.294526],
|
|
"files": ["file_a"],
|
|
"owner": str(user1_id),
|
|
"created_at": datetime.utcnow()
|
|
},
|
|
{
|
|
"title": f"Mont St Michel",
|
|
"description": "Description B",
|
|
"location": [48.636111, -1.511389],
|
|
"files": ["file_b"],
|
|
"owner": str(user1_id),
|
|
"created_at": datetime.utcnow()
|
|
},
|
|
{
|
|
"title": f"Eiffel Tower",
|
|
"description": "Description X",
|
|
"location": [48.858296, 2.294526],
|
|
"files": ["file_x"],
|
|
"owner": str(user2_id),
|
|
"created_at": datetime.utcnow()
|
|
},
|
|
{
|
|
"title": f"Mont Saint Michel",
|
|
"description": "Description Y",
|
|
"location": [48.636111, -1.511389],
|
|
"files": ["file_y"],
|
|
"owner": str(user2_id),
|
|
"created_at": datetime.utcnow()
|
|
}
|
|
])
|
|
|
|
if __name__ == "__main__":
|
|
populate_data()
|
|
print("Data inserted.")
|