~ubuntu-branches/ubuntu/trusty/d-rats/trusty

« back to all changes in this revision

Viewing changes to d_rats/callsigns.py

  • Committer: Bazaar Package Importer
  • Author(s): Steve Conklin
  • Date: 2011-02-18 18:17:24 UTC
  • Revision ID: james.westby@ubuntu.com-20110218181724-kaxw0ceawnu3wgw6
Tags: upstream-0.3.3~b5
ImportĀ upstreamĀ versionĀ 0.3.3~b5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import re
 
2
 
 
3
def find_us_callsigns(string):
 
4
    extra2x1 = "[aAkKnNwW][A-z][0-9][A-z]"
 
5
    others = "[aAkKnNwW][A-z]?[0-9][A-z]{2,3}"
 
6
 
 
7
    regex = "\\b(%s|%s)\\b" % (extra2x1, others)
 
8
 
 
9
    return re.findall(regex, string)
 
10
 
 
11
def find_au_callsigns(string):
 
12
    regex = '\\b[Vv][Kk][0-9][Ff]?[A-z]{2,3}'
 
13
 
 
14
    return re.findall(regex, string)
 
15
 
 
16
def find_ca_callsigns(string):
 
17
    regex = '[Vv][EeAa][0-9][A-z]{2,3}'
 
18
    
 
19
    return re.findall(regex, string)
 
20
 
 
21
callsign_functions = {
 
22
    "US" : find_us_callsigns,
 
23
    "Australia" : find_au_callsigns,
 
24
    "Canada" : find_ca_callsigns,
 
25
}
 
26
 
 
27
def find_callsigns(config, string):
 
28
    list = []
 
29
 
 
30
    cs = eval(config.get("prefs", "callsigns"))
 
31
    enabled = [y for x,y in cs if x]
 
32
 
 
33
    for t in callsign_functions.keys():
 
34
        if callsign_functions.has_key(t) and t in enabled:
 
35
            list += callsign_functions[t](string)
 
36
    
 
37
    return list