MCPcopy Create free account
hub / github.com/adobe/Marinus / main

Function main

python3_cron_scripts/whois_lookups.py:162–225  ·  view source on GitHub ↗

Begin Main...

(logger=None)

Source from the content-addressed store, hash-verified

160
161
162def main(logger=None):
163 """
164 Begin Main...
165 """
166 if logger is None:
167 logger = LoggingUtil.create_log(__name__)
168
169 now = datetime.now()
170 print("Starting: " + str(now))
171 logger.info("Starting...")
172
173 mongo_connector = RemoteMongoConnector.RemoteMongoConnector()
174 jobs_manager = JobsManager.JobsManager(mongo_connector, "whois_lookups")
175 jobs_manager.record_job_start()
176
177 # Collect the tracked zones...
178 zones = get_zones(mongo_connector)
179
180 whois_collection = mongo_connector.get_whois_connection()
181
182 for zone in zones:
183 # Ensure the zone contains at least one dot. This is left over from an old bug.
184 if zone.find(".") > 0:
185 logger.debug(zone)
186 zone_result = mongo_connector.perform_find_one(
187 whois_collection, {"zone": zone}
188 )
189
190 # If we haven't done a lookup in the past, try to collect the data.
191 # A limit exists on the number of whois lookups you can perform so limit to new domains.
192 if zone_result is None:
193 do_whois_lookup(logger, zone, whois_collection)
194
195 # The cap on the number of old entries to be updated.
196 MAX_OLD_ENTRIES = 400
197
198 # Grab entries that haven't been updated in 3 months
199 last_week = datetime.now() - timedelta(days=90, hours=1)
200 zone_result = whois_collection.find({"updated": {"$lte": last_week}}).batch_size(10)
201
202 i = 0
203 for result in zone_result:
204 do_whois_lookup(logger, result["zone"], whois_collection)
205 i = i + 1
206
207 # Chances are that a lot of the entries were inserted on the same day.
208 # This helps break updating old entries across different runs.
209 if i > MAX_OLD_ENTRIES:
210 break
211
212 # Delete old entries
213 last_year = datetime.now() - timedelta(days=365, hours=1)
214 zone_result = mongo_connector.perform_find(
215 whois_collection, {"updated": {"$lte": last_year}}, batch_size=10
216 )
217 for result in zone_result:
218 whois_collection.delete_one({"_id": ObjectId(result["_id"])})
219

Callers 1

whois_lookups.pyFile · 0.70

Calls 8

record_job_startMethod · 0.95
get_whois_connectionMethod · 0.95
record_job_completeMethod · 0.95
get_zonesFunction · 0.85
do_whois_lookupFunction · 0.85
create_logMethod · 0.80
perform_find_oneMethod · 0.80
perform_findMethod · 0.80

Tested by

no test coverage detected