Skip to content

Commit 1f51b42

Browse files
committed
reformatted with PEP8 style
1 parent fa88086 commit 1f51b42

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

get_mx_records.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env python
22
'''Usage: scriptname domain
3-
Output will the list of MX records sorted by MX, lowest MX value first, and highest Mx value last.
4-
This script uses PriorityQueue...Class was taken from Python Cookbook 3rd edition.
3+
Output will list of MX records of domain sorted by MX,
4+
lowest MX value first, and highest Mx value last.
5+
This script uses PriorityQueue Class and is based on
6+
Python Cookbook 3rd edition.
57
'''
68

79
__author__ = "Daniel T."
@@ -10,46 +12,50 @@
1012
__maintainer__ = "danasmera"
1113
__email__ = "[email protected]"
1214

13-
import os,sys
15+
import os
16+
import sys
1417
import heapq
1518

16-
maildomain=sys.argv[1]
19+
maildomain = sys.argv[1]
1720
# Use dig command
18-
mycommand="dig +short " + maildomain + " mx"
21+
mycommand = "dig +short " + maildomain + " mx"
22+
1923

2024
class PriorityQueue:
21-
def __init__(self):
22-
self._queue=[]
23-
self._index=0
25+
def __init__(self):
26+
self._queue = []
27+
self._index = 0
28+
29+
def push(self, item, priority):
30+
heapq.heappush(self._queue, (priority, self._index, item))
31+
self._index += 1
2432

25-
def push(self, item, priority):
26-
heapq.heappush(self._queue, (priority, self._index, item))
27-
self._index+=1
33+
def pop(self):
34+
return heapq.heappop(self._queue)[-1]
2835

29-
def pop(self):
30-
return heapq.heappop(self._queue)[-1]
36+
q = PriorityQueue()
3137

32-
q=PriorityQueue()
3338

3439
def push_mail_servers():
35-
counter=0
36-
with os.popen(mycommand) as fp:
37-
for line in fp:
38-
mail_servers = line.strip()
39-
priority, mail_server = mail_servers.split()
40-
q.push(mail_server, int(priority))
41-
counter+=1
40+
counter = 0
41+
with os.popen(mycommand) as fp:
42+
for line in fp:
43+
mail_servers = line.strip()
44+
priority, mail_server = mail_servers.split()
45+
q.push(mail_server, int(priority))
46+
counter += 1
4247
return counter
4348

49+
4450
def main():
45-
total_mx=push_mail_servers()
46-
while (total_mx > 0):
47-
print q.pop()
48-
total_mx-=1
51+
total_mx = push_mail_servers()
52+
while (total_mx > 0):
53+
print q.pop()
54+
total_mx -= 1
4955

5056
# Main
51-
if __name__=='__main__':
52-
main()
57+
if __name__ == '__main__':
58+
main()
5359

5460
'''Usage example
5561
[daniel@danasmera tmp]$ dig gmail.com mx +short

0 commit comments

Comments
 (0)