I'm creating a geoprocessing script and was told I should make it run at night when everyone is clocked out by communicating with the database. I haven't done that before so I asked for documentation for help. My supervisor gave me the below script that would allow me to do this; however, I'm confused as to where I am supposed to put my geoprocessing script within this database connection script. Here is the script that is supposed to communicate with the database and allow my script to be run at night:
# import packages
import os, arcpy, time, smtplib
# setup workspace and SDE databases in folder
for dirpath, dirnames, filenames in os.walk(r'//10.0.8.36/GIS/Software/Connection_dir/Test/'😞
for file in dirpath:
print(filenames)
string = r'//10.0.8.36/GIS/Software/Connection_dir/Test/'
new_list = [string + x for x in filenames]
print(new_list)
for database in new_list:
# Email users in database(s)
userList = arcpy.ListUsers(database)
print(userList)
# Block new connections to the database.
print('The database is no longer accepting connections.format{}'.format(database))
arcpy.AcceptConnections(database, False)
# Disconnect all users from the database.
print("Disconnecting all users")
arcpy.DisconnectUser(database, "ALL")
# Run the compress tool.
print("Running compress")
arcpy.Compress_management(database)
# Allow the database to begin accepting connections again
print("Allow users to connect to the database again")
arcpy.AcceptConnections(database, True)
# Rebuild indexes in database(s)
print("Rebuilding indexes on the system tables")
arcpy.RebuildIndexes_management(database, "SYSTEM")
# Updating statistics in database(s)
print('Updating statistics on the system tables.format{}'.format(database))
arcpy.AnalyzeDatasets_management(database, "SYSTEM")
print ("Finished")
break
break
I'm assuming my geoprocessing script would go after all of the code within the third for loop.