mirror of
https://github.com/r4sas/py-i2phosts
synced 2025-02-08 21:04:17 +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
|
# check for already existed hosts in database to avoid adding duplicates
|
||||||
# 1. do lookup by hostname
|
# 1. do lookup by hostname
|
||||||
# 2. do lookup by base64 hash
|
# 2. do lookup by base64 hash
|
||||||
if not i2phost.objects.filter(name=entry[0]) \
|
qs1 = i2phost.objects.filter(name=entry[0])
|
||||||
and not i2phost.objects.filter(b64hash=entry[1]):
|
qs2 = i2phost.objects.filter(name=entry[1])
|
||||||
print 'Adding %s' % entry[0]
|
if not qs1.exists() and not qs2.exists():
|
||||||
host = i2phost(name=entry[0], b64hash=entry[1],
|
print 'Adding %s' % entry[0]
|
||||||
description='Auto-added from external hosts.txt',
|
host = i2phost(name=entry[0], b64hash=entry[1],
|
||||||
activated=True)
|
description='Auto-added from external hosts.txt',
|
||||||
host.save()
|
activated=True)
|
||||||
|
host.save()
|
||||||
else:
|
else:
|
||||||
print 'Host %s already exists' % entry[0]
|
print 'Host %s already exists' % entry[0]
|
||||||
f.close()
|
f.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user