Compare commits
3 Commits
8b65584ac3
...
bb8a5d2dbc
Author | SHA1 | Date |
---|---|---|
Stefano Assenzo | bb8a5d2dbc | |
Stefano Assenzo | a945d9e72b | |
Stefano Assenzo | bf1f7bbf9b |
|
@ -3,3 +3,5 @@ test.xlsx
|
||||||
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())
|
||||||
|
|
||||||
|
@ -66,3 +65,11 @@ def check_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
|
||||||
|
@ -34,88 +37,418 @@ def update_time_school():
|
||||||
#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
|
||||||
|
teacher = ws.cell(row=i, column=column+1).value
|
||||||
|
if dont_repeat == 9:
|
||||||
|
check_repeat += 1 # 13
|
||||||
|
if check_repeat == 5:
|
||||||
|
check_repeat = 0
|
||||||
|
dont_repeat = 0
|
||||||
|
#number = 1
|
||||||
|
else:
|
||||||
|
if day == "None":
|
||||||
if school_subject == 0: #If school subject is 0, add "null" in MongoDB
|
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
|
number += 1
|
||||||
array_username = find_document_username[0]["_id"]
|
gagaga += 1
|
||||||
collection.update_one( # Add "null" in MongoDB beacause school subject is 0
|
dont_repeat += 1
|
||||||
{ "_id": ObjectId(array_username)},
|
if number == 9:
|
||||||
{
|
number = 1
|
||||||
"$push": { "School Subject": "null" }
|
if gagaga == 9:
|
||||||
}
|
gagaga = 0
|
||||||
)
|
|
||||||
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
|
else: #If school subject is not 0, add school subject in MongoDB
|
||||||
#remove_things_in_front = school_subject.split(' ', 1)[1]
|
#remove_things_in_front = school_subject.split(' ', 1)[1]
|
||||||
find_document_username = list(collection.find({}, {"Date": long_date})) #Find document in MongoDB
|
find_document_school_time_table = list(collection.find({}, {"Date": long_date}))
|
||||||
array_username = find_document_username[0]["_id"]
|
find_document_archive_school_time_table = list(collection_archive.find({}, {"Date": long_date}))
|
||||||
collection.update_one( # Add school subject in MongoDB beacause school subject is not 0
|
array_document_school_time_table = find_document_school_time_table[0]["_id"]
|
||||||
{ "_id": ObjectId(array_username)},
|
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
|
||||||
"$push": { "School Subject": school_subject }
|
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 school subject in MongoDB beacause school subject is not 0
|
collection_archive.update_one(
|
||||||
{ "_id": ObjectId(array_username)},
|
{ "_id": ObjectId(array_document_archive_school_time_table)},
|
||||||
{
|
{ "$set": {
|
||||||
"$push": { "School Subject": school_subject }
|
"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
|
||||||
|
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(
|
||||||
|
{ "_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
|
||||||
|
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
|
#Search teacher
|
||||||
for i in range(4, 80):
|
if dont_repeat_teacher == 9:
|
||||||
teacher = ws.cell(row=i, column=column+1).value
|
check_repeat_teacher += 1 # 13
|
||||||
column = column
|
if check_repeat_teacher == 5:
|
||||||
if teacher == 0: #If teacher is 0, add "null" in MongoDB
|
check_repeat_teacher = 0
|
||||||
find_document_username = list(collection.find({}, {"Date": long_date})) #Find document in MongoDB
|
dont_repeat_teacher = 0
|
||||||
array_username = find_document_username[0]["_id"]
|
#number = 1
|
||||||
collection.update_one( # Add "null" in MongoDB beacause teacher is 0
|
else:
|
||||||
{ "_id": ObjectId(array_username)},
|
if day == "None":
|
||||||
{
|
if teacher == 0:
|
||||||
"$push": { "Teacher": "null" }
|
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( # 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_teacher += 1
|
||||||
find_document_username = list(collection.find({}, {"Date": long_date}))
|
gagaga_teacher += 1
|
||||||
array_username = find_document_username[0]["_id"]
|
dont_repeat_teacher += 1
|
||||||
collection.update_one( # Add teacher in MongoDB beacause teacher is not 0
|
if number_teacher == 9:
|
||||||
{ "_id": ObjectId(array_username)},
|
number_teacher = 1
|
||||||
{
|
if gagaga_teacher == 8:
|
||||||
"$push": { "Teacher": teacher }
|
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( # 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,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
number_teacher += 1
|
||||||
|
gagaga_teacher += 1
|
||||||
|
dont_repeat_teacher += 1
|
||||||
|
if number_teacher == 9:
|
||||||
|
number_teacher = 1
|
||||||
|
if gagaga_teacher == 8:
|
||||||
|
gagaga_teacher = 0
|
||||||
|
|
||||||
os.remove(namefile_xlsx) #Delete excel file
|
update_time_school()
|
Loading…
Reference in New Issue