Last active
August 29, 2015 14:02
-
-
Save knu2xs/1a926cfaf2e97ebfa218 to your computer and use it in GitHub Desktop.
Test the provided credentials for teaching ARC4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| name: test_bon_logins.py | |
| author: Joel McCune (jmccune@esri.com) | |
| date: 02 Jun 2014 | |
| purpose: This script tests all the student credentials used for an ARC4 course. The results are, by default, written | |
| to a logfile created in the C:/Student directory. This location can be changed by providing an input for the | |
| optional output_dir parameter when calling the test_logins function. | |
| Please only use this as an initial preliminary test. Oddly enough, although all credentials were passing | |
| this test, some still were not working during an ARC4 course offering on 29 Apr 2014. Hence, although this | |
| utility can be used as an initial test, please also go back and spot check the instructor in addition to a | |
| few of the student credentials. | |
| """ | |
| # please set these variables before running the script | |
| credentials_root = 'cedar' | |
| credentials_pswd = '7frumpy.froido' | |
| # import modules | |
| import arcpy | |
| from os import path | |
| def test_logins(login_root, password, output_dir=r'C:\Student'): | |
| """ | |
| Test and log one series of credentials used for ARC4. | |
| :param login_root: This is the root of the credentials series. For example, if the series is cedar00-cedar15, the | |
| login_root will be cedar. | |
| :param password: This is the provided password for the credentials series. | |
| :param output_dir: This defaults to C:\Student. However, by providing this parameter to a valid directory, it can be | |
| changed. | |
| :return: | |
| """ | |
| # open a file to log results | |
| logfile = open(path.join(output_dir, 'bon_connection.log'), 'w') | |
| # two sets to store failed logins | |
| agol_failed = set() | |
| bon_failed = set() | |
| # for every login in the range from 00 to 15 | |
| for number in range(0, 16): | |
| # create username by assembling the login root and current looping number | |
| username = '{0}{1:0>2}'.format(login_root, number) | |
| # attempt to log into AGOL | |
| status_agol = arcpy.SignInToPortal_server( | |
| username=username, | |
| password=password, | |
| portal_url="http://trainingservices.maps.arcgis.com/" | |
| ).getOutput(0) | |
| # if the status is failed, add the user to the failed list | |
| if status_agol is False: | |
| agol_failed.add(username) | |
| # sign out from AGOL | |
| arcpy.SignOutFromPortal_server() | |
| # attempt to log into BON Portal | |
| status_bon = arcpy.SignInToPortal_server( | |
| username=username, | |
| password=password, | |
| portal_url="https://bon.esri.com/arcgis" | |
| ).getOutput(0) | |
| # sign out from BON | |
| arcpy.SignOutFromPortal_server() | |
| # if the status is failed, add the user to the failed list | |
| if status_bon is False: | |
| bon_failed.add(username) | |
| # log results for username | |
| logfile.write('{0} \\ {1}\n\tAGOL: {2}\n\tBON: {3}\n'.format(username, password, status_agol, status_bon)) | |
| # log failed agol usernames | |
| logfile.write('\nAGOL failed usernames:\n') | |
| for user in agol_failed: | |
| logfile.write('\n{0}'.format(user)) | |
| # log failed bon usernames | |
| logfile.write('\nAGOL failed usernames:\n') | |
| for user in bon_failed: | |
| logfile.write('\n{0}'.format(user)) | |
| # close logfile | |
| logfile.close() | |
| # provide for standalone execution, which is the only way this script is being distributed right now | |
| if __name__ == "__main__": | |
| # run this, baby! | |
| test_logins(credentials_root, credentials_pswd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment