-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanasonicNetgen.py
63 lines (41 loc) · 1.59 KB
/
panasonicNetgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/python3
import csv, re
csv_headers = [
'Enterprise ID', ' Group ID', ' Device Name',
' Device Type', ' UCount', ' Line Ports',
' New DName', ' New DType', ' User Agent'
]
def pana_net():
cnt = 0
phone_models = [
'600',
'500',
'HX4E'
]
ND_types = [
'Panasonic KX-TGP500',
'Linksys SPA-2102',
'HX4E',
'Panasonic KX-TGP600'
]
nw_device_type = {
'600': ND_types[3],
'500': ND_types[0],
'HX4E': ND_types[1]
}
with open('<YOUR CSV FILE HERE>', 'r') as csv_file:
contents = csv.DictReader(csv_file)
with open('<YOUR CSV FILE HERE>', 'a', newline='') as matched_file:
csv_writer = csv.DictWriter(matched_file, fieldnames=csv_headers, delimiter=',')
# csv_writer.writeheader()
for line in contents:
for model in phone_models:
pattern = re.compile(rf"(KX-TGP{model}|{model}-\d\w)")
matches = pattern.finditer(line[' User Agent'])
for match in matches:
if match.group(0) in line[' User Agent']:
line[' New DName'] = line[' Device Name']
line[' New DType'] = nw_device_type[model]
csv_writer.writerow(line)
cnt += 1
return cnt