2
2
3
3
# update/my_bp.py - script to download data from Malaysian government site
4
4
#
5
- # Copyright (C) 2013-2021 Arthur de Jong
5
+ # Copyright (C) 2013-2022 Arthur de Jong
6
6
#
7
7
# This library is free software; you can redistribute it and/or
8
8
# modify it under the terms of the GNU Lesser General Public
@@ -55,9 +55,9 @@ def parse(content):
55
55
tds = [clean (td ) for td in tr .findall ('td' )]
56
56
# table has two columns
57
57
if len (tds ) >= 2 and tds [0 ] and tds [1 ]:
58
- yield tds [0 ], tds [1 ]
58
+ yield tds [0 ], [ bp . strip () for bp in tds [1 ]. split ( ',' ) if re . match ( r' *[0-9]{2} *' , bp ) ]
59
59
if len (tds ) >= 4 and tds [2 ] and tds [3 ]:
60
- yield tds [2 ], tds [3 ]
60
+ yield tds [2 ], [ bp . strip () for bp in tds [3 ]. split ( ',' ) if re . match ( r' *[0-9]{2} *' , bp ) ]
61
61
62
62
63
63
if __name__ == '__main__' :
@@ -69,14 +69,15 @@ def parse(content):
69
69
response = requests .get (state_list_url , headers = headers , verify = 'update/my_bp.crt' , timeout = 30 )
70
70
response .raise_for_status ()
71
71
for state , bps in parse (response .content ):
72
- for bp in bps . split ( ',' ) :
73
- results [bp . strip () ]['state' ] = state
74
- results [bp . strip () ]['countries' ].add ('Malaysia' )
72
+ for bp in bps :
73
+ results [bp ]['state' ] = state
74
+ results [bp ]['countries' ].add ('Malaysia' )
75
75
# read the countries
76
76
response = requests .get (country_list_url , headers = headers , verify = 'update/my_bp.crt' , timeout = 30 )
77
77
response .raise_for_status ()
78
- for country , bp in parse (response .content ):
79
- results [bp ]['countries' ].add (country )
78
+ for cou
54DD
ntry , bps in parse (response .content ):
79
+ for bp in bps :
80
+ results [bp ]['countries' ].add (country )
80
81
# print the results
81
82
print ('# generated from National Registration Department of Malaysia, downloaded from' )
82
83
print ('# %s' % state_list_url )
0 commit comments