Repository navigation
Expand file tree
/
Copy pathAERIESScanFor8thGraders.py
More file actions
75 lines (71 loc) · 3.15 KB
/
Copy pathAERIESScanFor8thGraders.py
File metadata and controls
75 lines (71 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import io, ftplib, ssl, sys, os, datetime, json, gam, smtplib, logging
from sqlalchemy.engine import URL
from sqlalchemy import create_engine
from ldap3 import Server, Connection, ALL
from io import StringIO
from pathlib import Path
from timeit import default_timer as timer
import pandas as pd
from email.message import EmailMessage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from logging.handlers import SysLogHandler
"""
Python 3.11+
"""
if __name__ == '__main__':
start_of_timer = timer()
confighome = Path.home() / ".Acalanes" / "Acalanes.json"
with open(confighome) as f:
configs = json.load(f)
thelogger = logging.getLogger('MyLogger')
thelogger.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogHandler(address = (configs['logserveraddress'],514))
thelogger.addHandler(handler)
#prep status (msg) email
s = smtplib.SMTP(configs['SMTPServerAddress'])
msg = MIMEMultipart()
msg['From'] = configs['SMTPAddressFrom']
msg['To'] = 'edannewitz@auhsdschools.org'
DontDeleteFiles = False
WasThereAnError = False
filenamestring = 'csvtosheet.csv'
thelogger.info('AERIES Scan for New Students->Connecting To AERIESa')
connection_string = "DRIVER={SQL Server};SERVER=" + configs['AERIESSQLServer'] + ";DATABASE=" + configs['AERIESDatabase'] + ";UID=" + configs['AERIESUsername'] + ";PWD=" + configs['AERIESPassword'] + ";"
connection_url = URL.create("mssql+pyodbc", query={"odbc_connect": connection_string})
engine = create_engine(connection_url)
eighthgraders = f"""
SELECT SEM,* FROM STU WHERE GR = 8 AND SEM = '' AND SC < 8
"""
sql_query = pd.read_sql_query(eighthgraders, engine)
print(sql_query)
os.chdir('E:\\PythonTemp')
sql_query.to_csv(filenamestring,index=False)
sheetid = "1LS6y12eGNHJ9uG2i6Sswjr7Bata0ZmwZXPWyGZ-xYJ4"
TabName = "Test Tab 3"
UserEmail = "edannewitz@auhsdschools.org"
gam.initializeLogging()
stat1 = gam.CallGAMCommand(['gam', 'user', UserEmail, 'update', 'drivefile', 'id', sheetid,'localfile',filenamestring,'addsheet',TabName])
exit(1)
if stat1 != 0:
WasThereAnError = True
thelogger.critical('UpdateStudentListsInGoogle->GAM returned an error for the last command')
if not DontDeleteFiles:
try:
os.remove(filenamestring)
except:
print('Error')
print('Done')
"""
msgbody += f"Error removing {campus[0]} ALL grades list.\n"
thelogger.critical(f"UpdateStudentListsInGoogle->Error trying to remove file {counselor[1]} ALL Grades list csv")
msgbody += f"Synced Students-> All list. Gam Status->{stat1}\n"
if WasThereAnError:
msg['Subject'] = "ERROR! " + str(configs['SMTPStatusMessage'] + " AERIES New Student Scan " + datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y"))
else:
msg['Subject'] = str(configs['SMTPStatusMessage'] + " AERIES New Student Scan " + datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y"))
msg.attach(MIMEText(html_body,'html'))
s = smtplib.SMTP(configs['SMTPServerAddress'])
s.send_message(msg)
"""