|
1 | 1 | # Class: sendDataMongoDB |
2 | | -# Last updated: 2023/03/25 |
3 | | -# Author: TheScriptGuy (https://github.com/TheScriptGuy |
4 | | -# Version: 0.09 |
| 2 | +# Last updated: 2023/04/15 |
| 3 | +# Author: TheScriptGuy (https://github.com/TheScriptGuy) |
| 4 | +# Version: 0.10 |
5 | 5 | # Description: Send json list to mongoDB based on configuration in mongo.cfg |
6 | 6 |
|
7 | 7 | import pymongo |
@@ -107,13 +107,20 @@ def sendResults(self, __results, __destCollection): |
107 | 107 | __mongoResult = __destCollection.insert_one(__results) |
108 | 108 | __uploadResult.append(__mongoResult) |
109 | 109 | except pymongo.errors.ServerSelectionTimeoutError: |
110 | | - print("Server connection timeout error when uploading data.") |
111 | | - print("Saving to certificateData.json") |
| 110 | + # Get time of error |
| 111 | + errTime = str(datetime.datetime.utcnow()) |
| 112 | + print(f"{errTime} - Server connection timeout error when uploading data. Saving to certificateData.json") |
| 113 | + |
| 114 | + # Save test data to file. |
112 | 115 | self.sendJsonScriptDataToFile("certificateData.json", [__results]) |
113 | 116 | sys.exit(1) |
| 117 | + |
114 | 118 | except pymongo.errors.OperationFailure as e: |
115 | | - print(f"Mongo operation error - {e}") |
116 | | - print("Saving to certificateData.json") |
| 119 | + # Get time of error |
| 120 | + errTime = str(datetime.datetime.utcnow()) |
| 121 | + print(f"{errTime} - Mongo operation error - {e}. Saving to certificateData.json") |
| 122 | + |
| 123 | + # Save test data to file. |
117 | 124 | self.sendJsonScriptDataToFile("certificateData.json", [__results]) |
118 | 125 | sys.exit(1) |
119 | 126 |
|
@@ -233,4 +240,4 @@ def uploadDataToMongoDB(self, __jsonScriptData): |
233 | 240 | def __init__(self): |
234 | 241 | """Initialize the sendDataMongoDB class.""" |
235 | 242 | self.initialized = True |
236 | | - self.version = "0.09" |
| 243 | + self.version = "0.10" |
0 commit comments