Advertisement
Guest User

Untitled

a guest
Apr 20th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. #!/usr/bin/python
  2. from lxml import etree
  3.  
  4. # input:
  5. # <RangeEntry minFrequency="" maxFrequency="" mode="" step="" color=""></RangeEntry>
  6.  
  7. # output:
  8. ## Tag name          ;  color
  9. #AM                  ; #c0c0c0
  10. #
  11. ## Frequency ; Name                     ; Modulation          ;  Bandwidth; Tags
  12. # 500000; 123                      ; LSB                 ;       2700; Untagged
  13. # 579800; 321                      ; Narrow FM           ;      10000; Untagged
  14. # 596400; ttt                      ; AM                  ;      10000; Untagged
  15. # 596400; ttt                      ; CW-L                ;        500; Untagged
  16.  
  17. modulation_mapping = {
  18.     'AM': {'mode': 'AM', 'bandwidth': 10000},
  19.     'LSB': {'mode': 'LSB', 'bandwidth': 2700},
  20.     'USB': {'mode': 'USB', 'bandwidth': 2700},
  21.     'CW': {'mode': 'CW-L', 'bandwidth': 500},
  22.     'NFM': {'mode': 'Narrow FM', 'bandwidth': 10000},
  23.     'WFM': {'mode': 'WFM (mono)', 'bandwidth': 160000},}
  24.  
  25. with open('BandPlan.xml') as input:
  26.     tree = etree.parse(input)
  27.     data = tree.xpath('/ArrayOfRangeEntry/*')
  28.  
  29.     print("""# Tag name; color
  30. Untagged; #c0c0c0
  31.  
  32. # Frequency; Name; Modulation;  Bandwidth; Tags""")
  33.  
  34.     for record in data:
  35.         print('{0}; {1}; {2}; {3}; {4}'.format(record.get('minFrequency'), '{0} ['.format(record.text), modulation_mapping[record.get('mode')]['mode'], modulation_mapping[record.get('mode')]['bandwidth'], 'Untagged'))
  36.         print('{0}; {1}; {2}; {3}; {4}'.format(record.get('maxFrequency'), '{0} ]'.format(record.text), modulation_mapping[record.get('mode')]['mode'], modulation_mapping[record.get('mode')]['bandwidth'], 'Untagged'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement