Compare commits
3 Commits
8b65584ac3
...
bb8a5d2dbc
Author | SHA1 | Date |
---|---|---|
Stefano Assenzo | bb8a5d2dbc | |
Stefano Assenzo | a945d9e72b | |
Stefano Assenzo | bf1f7bbf9b |
|
@ -2,4 +2,6 @@ test.xlsx
|
||||||
.env
|
.env
|
||||||
geckodriver.log
|
geckodriver.log
|
||||||
all.log
|
all.log
|
||||||
__pycache__
|
__pycache__
|
||||||
|
test.py
|
||||||
|
school_time.xlsx
|
|
@ -1,5 +1,3 @@
|
||||||
from update_time_school import update_time_school
|
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from imbox import Imbox
|
from imbox import Imbox
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
@ -35,7 +33,6 @@ def check_email():
|
||||||
|
|
||||||
mail = Imbox(HOST, username=USERNAME, password=PASSWORD, ssl=True, ssl_context=None, starttls=False) # Connect to IMAP Server
|
mail = Imbox(HOST, username=USERNAME, password=PASSWORD, ssl=True, ssl_context=None, starttls=False) # Connect to IMAP Server
|
||||||
messages = mail.messages(sent_from=EMAIL_SCHOOL, unread=True) # Get unread emails from school
|
messages = mail.messages(sent_from=EMAIL_SCHOOL, unread=True) # Get unread emails from school
|
||||||
|
|
||||||
for (uid, message) in messages:
|
for (uid, message) in messages:
|
||||||
mail.mark_seen(uid)
|
mail.mark_seen(uid)
|
||||||
|
|
||||||
|
@ -43,6 +40,7 @@ def check_email():
|
||||||
for idx, attachment in enumerate(message.attachments):
|
for idx, attachment in enumerate(message.attachments):
|
||||||
try:
|
try:
|
||||||
att_fn = attachment.get('filename') # Get attachment filename
|
att_fn = attachment.get('filename') # Get attachment filename
|
||||||
|
print(att_fn)
|
||||||
download_path = f"{DOWNLOAD_FOLDER}/{att_fn}"
|
download_path = f"{DOWNLOAD_FOLDER}/{att_fn}"
|
||||||
extension_file = pathlib.Path(att_fn).suffix # Get extension file
|
extension_file = pathlib.Path(att_fn).suffix # Get extension file
|
||||||
print(extension_file)
|
print(extension_file)
|
||||||
|
@ -51,13 +49,14 @@ def check_email():
|
||||||
else:
|
else:
|
||||||
if collection.find_one({"filename": att_fn}):
|
if collection.find_one({"filename": att_fn}):
|
||||||
print("File already exists")
|
print("File already exists")
|
||||||
|
recheck_email()
|
||||||
else:
|
else:
|
||||||
with open(download_path, "wb") as fp:
|
with open(download_path, "wb") as fp:
|
||||||
fp.write(attachment.get('content').read())
|
fp.write(attachment.get('content').read())
|
||||||
os.rename(download_path, f"{DOWNLOAD_FOLDER}/school_time.xlsx") # Rename file
|
os.rename(download_path, f"{DOWNLOAD_FOLDER}/school_time.xlsx") # Rename file
|
||||||
collection.delete_many({}) # Delete old file
|
collection.delete_many({}) # Delete old file
|
||||||
collection.insert_one({"filename": att_fn}) # Insert filename to MongoDB
|
collection.insert_one({"filename": att_fn}) # Insert filename to MongoDB
|
||||||
update_time_school() # Update school time table
|
send_xlsx()
|
||||||
except:
|
except:
|
||||||
print(traceback.print_exc())
|
print(traceback.print_exc())
|
||||||
|
|
||||||
|
@ -65,4 +64,12 @@ def check_email():
|
||||||
recheck_email()
|
recheck_email()
|
||||||
except:
|
except:
|
||||||
print(traceback.print_exc())
|
print(traceback.print_exc())
|
||||||
recheck_email()
|
recheck_email()
|
||||||
|
|
||||||
|
def send_xlsx():
|
||||||
|
from update_time_school import update_time_school
|
||||||
|
update_time_school()
|
||||||
|
os.remove(f"{DOWNLOAD_FOLDER}/school_time.xlsx") # Delete file
|
||||||
|
recheck_email()
|
||||||
|
|
||||||
|
check_email()
|
|
@ -1,10 +1,11 @@
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId
|
||||||
|
from openpyxl.styles import NamedStyle
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import openpyxl as xl
|
import openpyxl as xl
|
||||||
import datetime
|
import datetime
|
||||||
import pymongo
|
import pymongo
|
||||||
import urllib
|
import urllib
|
||||||
import time
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
load_dotenv() #Load .env file
|
load_dotenv() #Load .env file
|
||||||
|
@ -20,6 +21,8 @@ def update_time_school():
|
||||||
# Load excel file
|
# Load excel file
|
||||||
namefile_xlsx = "attachments/school_time.xlsx"
|
namefile_xlsx = "attachments/school_time.xlsx"
|
||||||
workbook = xl.load_workbook(filename=namefile_xlsx)
|
workbook = xl.load_workbook(filename=namefile_xlsx)
|
||||||
|
date_style = NamedStyle(name='date_style',number_format='dd/mm/yy')
|
||||||
|
workbook.add_named_style(date_style)
|
||||||
ws = workbook.active
|
ws = workbook.active
|
||||||
|
|
||||||
#Date
|
#Date
|
||||||
|
@ -32,90 +35,420 @@ def update_time_school():
|
||||||
long_date = day + "-" + month + "-" + year + " " + hour + ":" + minute
|
long_date = day + "-" + month + "-" + year + " " + hour + ":" + minute
|
||||||
|
|
||||||
#Create collection
|
#Create collection
|
||||||
mydict = {
|
mydict = {
|
||||||
"Date": long_date,
|
"Date": long_date,
|
||||||
"School Subject": [],
|
"School Subject": {
|
||||||
"Teacher": [],
|
"Monday": [
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"Tuesday": [
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"Wednesday": [
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"Thursday": [
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"Friday": [
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"Saturday": [
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Subject": "null",
|
||||||
|
"Teacher": "null",
|
||||||
|
},
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
}
|
||||||
x = collection.delete_many({}) #Delete all documents in collection (school-time-table)
|
x = collection.delete_many({}) #Delete all documents in collection (school-time-table)
|
||||||
x = collection.insert_one(mydict) # Add collection on collection (school-time-table)
|
x = collection.insert_one(mydict) # Add collection on collection (school-time-table)
|
||||||
x = collection_archive.insert_one(mydict) # Add collection on collection (archive-school-time-table)
|
x = collection_archive.insert_one(mydict) # Add collection on collection (archive-school-time-table)
|
||||||
|
check_repeat = 0
|
||||||
|
check_repeat_teacher = 0
|
||||||
|
dont_repeat = 0
|
||||||
|
dont_repeat_teacher = 0
|
||||||
|
gagaga_teacher = 0
|
||||||
|
number_teacher = 1
|
||||||
|
number = 1
|
||||||
|
current_day = None
|
||||||
|
day_counter = 0
|
||||||
|
number_day = 0
|
||||||
#Search my class in excel file and add in MongoDB
|
#Search my class in excel file and add in MongoDB
|
||||||
|
number = 1
|
||||||
|
gagaga = 0
|
||||||
for row in range (1, 100):
|
for row in range (1, 100):
|
||||||
# column B ~ column F
|
# column B ~ column F
|
||||||
for column in range (1, 100):
|
for column in range (1, 100):
|
||||||
cell = ws.cell(row, column)
|
cell = ws.cell(row, column)
|
||||||
if cell.value == "2elci":
|
if cell.value == "2elci":
|
||||||
ws.cell(row=cell.row, column=column).value
|
|
||||||
#Search school time table
|
#Search school time table
|
||||||
for i in range(4,80):
|
for i in range(4,80):
|
||||||
|
day = str(ws.cell(row=i, column=3).value) # Get day from excel file
|
||||||
school_subject = ws.cell(row=i, column=column).value # Get school subject from excel file
|
school_subject = ws.cell(row=i, column=column).value # Get school subject from excel file
|
||||||
if school_subject == 0: #If school subject is 0, add "null" in MongoDB
|
|
||||||
find_document_username = list(collection.find({}, {"Date": long_date})) #Find document in MongoDB
|
|
||||||
array_username = find_document_username[0]["_id"]
|
|
||||||
collection.update_one( # Add "null" in MongoDB beacause school subject is 0
|
|
||||||
{ "_id": ObjectId(array_username)},
|
|
||||||
{
|
|
||||||
"$push": { "School Subject": "null" }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
collection_archive.update_one( # Add "null" in MongoDB beacause school subject is 0
|
|
||||||
{ "_id": ObjectId(array_username)},
|
|
||||||
{
|
|
||||||
"$push": { "School Subject": "null" }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else: #If school subject is not 0, add school subject in MongoDB
|
|
||||||
#remove_things_in_front = school_subject.split(' ', 1)[1]
|
|
||||||
find_document_username = list(collection.find({}, {"Date": long_date})) #Find document in MongoDB
|
|
||||||
array_username = find_document_username[0]["_id"]
|
|
||||||
collection.update_one( # Add school subject in MongoDB beacause school subject is not 0
|
|
||||||
{ "_id": ObjectId(array_username)},
|
|
||||||
{
|
|
||||||
"$push": { "School Subject": school_subject }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
collection_archive.update_one( # Add school subject in MongoDB beacause school subject is not 0
|
|
||||||
{ "_id": ObjectId(array_username)},
|
|
||||||
{
|
|
||||||
"$push": { "School Subject": school_subject }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
#Search teacher
|
|
||||||
for i in range(4, 80):
|
|
||||||
teacher = ws.cell(row=i, column=column+1).value
|
teacher = ws.cell(row=i, column=column+1).value
|
||||||
column = column
|
if dont_repeat == 9:
|
||||||
if teacher == 0: #If teacher is 0, add "null" in MongoDB
|
check_repeat += 1 # 13
|
||||||
find_document_username = list(collection.find({}, {"Date": long_date})) #Find document in MongoDB
|
if check_repeat == 5:
|
||||||
array_username = find_document_username[0]["_id"]
|
check_repeat = 0
|
||||||
collection.update_one( # Add "null" in MongoDB beacause teacher is 0
|
dont_repeat = 0
|
||||||
{ "_id": ObjectId(array_username)},
|
#number = 1
|
||||||
{
|
else:
|
||||||
"$push": { "Teacher": "null" }
|
if day == "None":
|
||||||
|
if school_subject == 0: #If school subject is 0, add "null" in MongoDB
|
||||||
|
number += 1
|
||||||
|
gagaga += 1
|
||||||
|
dont_repeat += 1
|
||||||
|
if number == 9:
|
||||||
|
number = 1
|
||||||
|
if gagaga == 9:
|
||||||
|
gagaga = 0
|
||||||
|
else: #If school subject is not 0, add school subject in MongoDB
|
||||||
|
#remove_things_in_front = school_subject.split(' ', 1)[1]
|
||||||
|
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||||
|
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||||
|
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||||
|
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||||
|
# Add school subject in MongoDB beacause school subject is not 0
|
||||||
|
collection.update_one(
|
||||||
|
{ "_id": ObjectId(array_document_school_time_table)},
|
||||||
|
{ "$set": {
|
||||||
|
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": school_subject,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
collection_archive.update_one( # Add "null" in MongoDB beacause teacher is 0
|
collection_archive.update_one(
|
||||||
{ "_id": ObjectId(array_username)},
|
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||||
{
|
{ "$set": {
|
||||||
"$push": { "Teacher": teacher }
|
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": school_subject,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else: #If teacher is not 0, add teacher in MongoDB
|
number += 1
|
||||||
find_document_username = list(collection.find({}, {"Date": long_date}))
|
gagaga += 1
|
||||||
array_username = find_document_username[0]["_id"]
|
dont_repeat += 1
|
||||||
collection.update_one( # Add teacher in MongoDB beacause teacher is not 0
|
if number == 9:
|
||||||
{ "_id": ObjectId(array_username)},
|
number = 1
|
||||||
{
|
if gagaga == 8:
|
||||||
"$push": { "Teacher": teacher }
|
gagaga = 0
|
||||||
|
else:
|
||||||
|
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y")
|
||||||
|
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A')
|
||||||
|
array_test = []
|
||||||
|
array_test.append(convert_date_to_day)
|
||||||
|
number_day += 1
|
||||||
|
if school_subject == 0: #If school subject is 0, add "null" in MongoDB
|
||||||
|
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||||
|
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||||
|
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||||
|
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||||
|
collection.update_one(
|
||||||
|
{ "_id": ObjectId(array_document_school_time_table)},
|
||||||
|
{ "$set": {
|
||||||
|
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": school_subject,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
collection_archive.update_one( # Add teacher in MongoDB beacause teacher is not 0
|
collection_archive.update_one(
|
||||||
{ "_id": ObjectId(array_username)},
|
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||||
{
|
{ "$set": {
|
||||||
"$push": { "Teacher": teacher }
|
"School Subject." + array_test[0] + "." + str(gagaga) + ".Subject": school_subject,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
os.remove(namefile_xlsx) #Delete excel file
|
number += 1
|
||||||
|
gagaga += 1
|
||||||
|
dont_repeat += 1
|
||||||
|
number = 0
|
||||||
|
if number == 9:
|
||||||
|
number = 1
|
||||||
|
if gagaga == 8:
|
||||||
|
gagaga = 0
|
||||||
|
else: #If school subject is not 0, add school subject in MongoDB
|
||||||
|
#remove_things_in_front = school_subject.split(' ', 1)[1]
|
||||||
|
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||||
|
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||||
|
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||||
|
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||||
|
# Add school subject in MongoDB beacause school subject is not 0
|
||||||
|
collection.update_one(
|
||||||
|
{ "_id": ObjectId(array_document_school_time_table)},
|
||||||
|
{ "$set": {
|
||||||
|
"School Subject." + array_test[0] + "." + str(gagaga)+ ".Subject": school_subject,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
collection_archive.update_one(
|
||||||
|
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||||
|
{ "$set": {
|
||||||
|
"School Subject." + array_test[0] + "." + str(gagaga)+ ".Subject": school_subject,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
number += 1
|
||||||
|
gagaga += 1
|
||||||
|
dont_repeat += 1
|
||||||
|
if number == 9:
|
||||||
|
number = 1
|
||||||
|
if gagaga == 8:
|
||||||
|
gagaga = 0
|
||||||
|
|
||||||
|
#Search teacher
|
||||||
|
if dont_repeat_teacher == 9:
|
||||||
|
check_repeat_teacher += 1 # 13
|
||||||
|
if check_repeat_teacher == 5:
|
||||||
|
check_repeat_teacher = 0
|
||||||
|
dont_repeat_teacher = 0
|
||||||
|
#number = 1
|
||||||
|
else:
|
||||||
|
if day == "None":
|
||||||
|
if teacher == 0:
|
||||||
|
number_teacher += 1
|
||||||
|
gagaga_teacher += 1
|
||||||
|
dont_repeat_teacher += 1
|
||||||
|
if number_teacher == 9:
|
||||||
|
number_teacher = 1
|
||||||
|
if gagaga_teacher == 9:
|
||||||
|
gagaga_teacher = 0
|
||||||
|
else:
|
||||||
|
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||||
|
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||||
|
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||||
|
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||||
|
collection.update_one(
|
||||||
|
{ "_id": ObjectId(array_document_school_time_table)},
|
||||||
|
{ "$set": {
|
||||||
|
"School Subject." + array_test[0] + "." + str(gagaga_teacher) + ".Teacher": teacher,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
collection_archive.update_one(
|
||||||
|
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||||
|
{ "$set": {
|
||||||
|
"School Subject." + array_test[0] + "." + str(gagaga)+ ".Subject": school_subject,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
number_teacher += 1
|
||||||
|
gagaga_teacher += 1
|
||||||
|
dont_repeat_teacher += 1
|
||||||
|
if number_teacher == 9:
|
||||||
|
number_teacher = 1
|
||||||
|
if gagaga_teacher == 8:
|
||||||
|
gagaga_teacher = 0
|
||||||
|
else:
|
||||||
|
datetime_obj = datetime.datetime.strptime(day, "%Y-%m-%d %H:%M:%S").strftime("%d %m %Y")
|
||||||
|
convert_date_to_day = datetime.datetime.strptime(datetime_obj, '%d %m %Y').strftime('%A')
|
||||||
|
array_test = []
|
||||||
|
array_test.append(convert_date_to_day)
|
||||||
|
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||||
|
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||||
|
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||||
|
array_document_archive_school_time_table = find_document_archive_school_time_table[0]["_id"]
|
||||||
|
collection.update_one(
|
||||||
|
{ "_id": ObjectId(array_document_school_time_table)},
|
||||||
|
{ "$set": {
|
||||||
|
"School Subject." + array_test[0] + "." + str(gagaga_teacher)+ ".Teacher": teacher,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
collection_archive.update_one(
|
||||||
|
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||||
|
{ "$set": {
|
||||||
|
"School Subject." + array_test[0] + "." + str(gagaga)+ ".Subject": school_subject,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
number_teacher += 1
|
||||||
|
gagaga_teacher += 1
|
||||||
|
dont_repeat_teacher += 1
|
||||||
|
if number_teacher == 9:
|
||||||
|
number_teacher = 1
|
||||||
|
if gagaga_teacher == 8:
|
||||||
|
gagaga_teacher = 0
|
||||||
|
|
||||||
|
update_time_school()
|
Loading…
Reference in New Issue