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.
54 lines
1.5 KiB
54 lines
1.5 KiB
from montydb import MontyClient |
|
from datetime import datetime, timedelta |
|
import json |
|
|
|
# Create a connection |
|
conn = MontyClient("db") |
|
|
|
# Access your database and collection |
|
db = conn.letsswing |
|
collection = db.livelli |
|
|
|
# Insert a document with a nested structure |
|
|
|
# jsonfile = open('file.json', 'r') |
|
|
|
# for row in jsonfile: |
|
# print(row) |
|
# collection.insert_one({"id":"3","nome":"Advanced"}) |
|
# collection.insert_one({"id":"2","nome":"Improver"}) |
|
# collection.insert_one({"id":"1","nome":"Beginners"}) |
|
|
|
|
|
collection = db.lezioni |
|
|
|
# collection.insert_one({'}) |
|
|
|
|
|
# Start from a known Monday. |
|
start_date = datetime(2023,10,1) |
|
|
|
while start_date.weekday() != 0: # 0 represents Monday in weekday() |
|
start_date -= timedelta(days=1) |
|
|
|
|
|
for i in range(36): # We need 10 weeks to get 20 days (2 days per week) |
|
monday = start_date + timedelta(weeks=i) |
|
wednesday1 = monday + timedelta(days=2) # Wednesday is two days after Monday |
|
monday = monday.replace(hour=19, minute=30) |
|
wednesday1= wednesday1.replace(hour=19, minute=30) |
|
wednesday2 = wednesday1 |
|
wednesday2 = wednesday2.replace(hour=20, minute=30) |
|
|
|
collection.insert_one({"sede": 1, "livello":1, "data":monday.strftime('%Y-%m-%d %H:%M:%S')}) |
|
collection.insert_one({"sede": 0, "livello":1, "data":wednesday1.strftime('%Y-%m-%d %H:%M:%S')}) |
|
collection.insert_one({"sede": 0, "livello":2, "data":wednesday2.strftime('%Y-%m-%d %H:%M:%S')}) |
|
|
|
|
|
|
|
|
|
|
|
# # results = collection.find({"sede": 1}) |
|
|
|
# # for result in results: |
|
# # print(result)
|
|
|