mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-02-08 12:54:23 +00:00
injector: use more efficient exists() method
This commit is contained in:
parent
bc33f75238
commit
b71f2fc511
15
injector
15
injector
@ -19,13 +19,14 @@ for line in f:
|
||||
# check for already existed hosts in database to avoid adding duplicates
|
||||
# 1. do lookup by hostname
|
||||
# 2. do lookup by base64 hash
|
||||
if not i2phost.objects.filter(name=entry[0]) \
|
||||
and not i2phost.objects.filter(b64hash=entry[1]):
|
||||
print 'Adding %s' % entry[0]
|
||||
host = i2phost(name=entry[0], b64hash=entry[1],
|
||||
description='Auto-added from external hosts.txt',
|
||||
activated=True)
|
||||
host.save()
|
||||
qs1 = i2phost.objects.filter(name=entry[0])
|
||||
qs2 = i2phost.objects.filter(name=entry[1])
|
||||
if not qs1.exists() and not qs2.exists():
|
||||
print 'Adding %s' % entry[0]
|
||||
host = i2phost(name=entry[0], b64hash=entry[1],
|
||||
description='Auto-added from external hosts.txt',
|
||||
activated=True)
|
||||
host.save()
|
||||
else:
|
||||
print 'Host %s already exists' % entry[0]
|
||||
f.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user