Ejemplo n.º 1
0
 def updateAward( idParams, awState, cfmTypes ):
     updParams = {}
     cfm = {}
     if not cfmTypes:
         cfmTypes = cfmFields.keys()
     awLookup = dxdb.getObject( 'user_awards', idParams, False, True )
     if awLookup:
         updateFl = False
         for cfmType in cfmTypes:
             if cfmFields.has_key(cfmType) and not awLookup[cfmType] \
                 and awState[cfmType]:
                 updParams[cfmType] = True
                 updateFl = True
             cfm[cfmType] = (awLookup['cfm'].has_key(cfmType) and \
                 awLookup['cfm'][cfmType]) or \
                 ( awState.has_key( cfmType ) and awState[cfmType] )
         updParams['cfm'] = json.dumps( cfm )
         csCount = 0 if not awLookup['worked_cs'] else \
                 2 if ',' in awLookup['worked_cs'] else 1
         if csCount < 2:
             workedCs = awLookup['worked_cs'] \
                     if awLookup['worked_cs'] else ''
             for cs in awState['callsigns']:
                 if not cs in workedCs:
                     workedCs += ', ' + cs if workedCs else cs
                     csCount += 1
                     updateFl = True
                     if csCount > 1:
                             break
             updParams['worked_cs'] = workedCs
         if updateFl:                        
             dxdb.paramUpdate( 'user_awards', idParams, updParams )
             return True
     else:
         updParams = idParams.copy()
         updParams['worked_cs'] = ', '.join( awState['callsigns'] )
         cfm = {}
         for cfmType in cfmTypes:
             if cfmFields.has_key( cfmType ):
                 updParams[cfmType] = awState[cfmType]
             cfm[cfmType] = ( awState.has_key( cfmType ) \
                     and awState[cfmType] )
         updParams['cfm'] = json.dumps( cfm )
         dxdb.getObject( 'user_awards', updParams, True )
         return True
Ejemplo n.º 2
0
 def updateAward(idParams, awState, cfmTypes):
     updParams = {}
     cfm = {}
     if not cfmTypes:
         cfmTypes = cfmFields.keys()
     awLookup = dxdb.getObject('user_awards', idParams, False, True)
     if awLookup:
         updateFl = False
         for cfmType in cfmTypes:
             if cfmFields.has_key(cfmType) and not awLookup[cfmType] \
                 and awState[cfmType]:
                 updParams[cfmType] = True
                 updateFl = True
             cfm[cfmType] = (awLookup['cfm'].has_key(cfmType) and \
                 awLookup['cfm'][cfmType]) or \
                 ( awState.has_key( cfmType ) and awState[cfmType] )
         updParams['cfm'] = json.dumps(cfm)
         csCount = 0 if not awLookup['worked_cs'] else \
                 2 if ',' in awLookup['worked_cs'] else 1
         if csCount < 2:
             workedCs = awLookup['worked_cs'] \
                     if awLookup['worked_cs'] else ''
             for cs in awState['callsigns']:
                 if not cs in workedCs:
                     workedCs += ', ' + cs if workedCs else cs
                     csCount += 1
                     updateFl = True
                     if csCount > 1:
                         break
             updParams['worked_cs'] = workedCs
         if updateFl:
             dxdb.paramUpdate('user_awards', idParams, updParams)
             return True
     else:
         updParams = idParams.copy()
         updParams['worked_cs'] = ', '.join(awState['callsigns'])
         cfm = {}
         for cfmType in cfmTypes:
             if cfmFields.has_key(cfmType):
                 updParams[cfmType] = awState[cfmType]
             cfm[cfmType] = ( awState.has_key( cfmType ) \
                     and awState[cfmType] )
         updParams['cfm'] = json.dumps(cfm)
         dxdb.getObject('user_awards', updParams, True)
         return True
Ejemplo n.º 3
0
 def updateDB(self):
     if self.offDB:
         return
     if self.inDB:
         dxdb.updateObject( 'callsigns',
           { 'callsign': self.cs, 'qth': self.gridsquare, \
                   'district': self.district, 'region': self.region,\
                   'qrz_data_loaded': self.qrzData, \
                   'special_cs': self.special,\
                   'iota': self.iota }, 'callsign' )
     else:
         dxdb.getObject( 'callsigns', \
                 { 'callsign': self.cs, 'region': self.region, \
                 'district': self.district,\
                 'qth': self.gridsquare, 'qrz_data_loaded': self.qrzData, \
                 'iota':self.iota,
                 'country': self.country, 'special_cs': self.special,  }, \
                 True )
         dxdb.commit()
         self.inDB = True
     if self.special:
         updateSpecialLists()
Ejemplo n.º 4
0
#!/usr/bin/python
#coding=utf-8

from twisted.internet import reactor, task, defer
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.internet.defer import DeferredQueue
from twisted.conch.telnet import TelnetTransport, StatefulTelnetProtocol
from twisted.python import log
import sys, decimal, re, datetime, os, logging, time, json, urllib2, xmltodict, jwt

from common import appRoot, readConf, siteConf, loadJSON
from dxdb import dxdb, dbConn, cursor2dicts
from dx_t import DX

print dxdb.getObject( 'users', { 'callsign': 'QQQQ' } )




Ejemplo n.º 5
0
        if not jcc['values'].has_key( params['upd']['region'].upper() + ' ' + \
                params['upd']['district'] ):
            params['upd']['district'] = ''
            params['upd']['region'] = ''

        ku = ''
        if len( data ) >= kuColumn:
            for kuPfx in ( params['upd']['region'], params['upd']['district'] ):
                if waku['values'].has_key( kuPfx + ' ' + data[kuColumn] ):
                    ku = kuPfx + ' ' + data[kuColumn]

        if params['upd']['district'] or params['upd']['region'] or ku:
            params['upd']['region'] = params['region'].upper()
            params['district'] = params['region
            if not dxdb.getObject( 'callsigns', { 'callsign': params['callsign'] }, \
                    False, True ):
                dxdb.getObject( 'callsigns', params, True )
            if ku and not dxdb.getObject( 'awards', \
                { 'callsign': params['callsign'], 'award': 'WAKU' }, False, True ):
                dxdb.getObject( 'awards', 
                    { 'callsign': params['callsign'], \
                        'award': 'WAKU', \
                        'value': ku }, True )

        data = getSplitLine( file )
    dxdb.commit()



Ejemplo n.º 6
0
    def __init__(self, dxData=None, newSpot=False, **params):
        self.isBeacon = False
        self._district = None
        self.region = None
        self.iota = None
        self.offDB = False
        self.pfx = None
        self.awards = {}
        self.dxData = dxData
        self.country = None
        self.special = False
        try:
            self.text = params['text'].decode('utf-8',
                                              'ignore').encode("utf-8")
        except Exception as ex:
            logging.error("Error decoding qso text:")
            logging.error(params['text'])
            logging.exception(ex)
            self.text = ''

        self.freq = params['freq']
        self.cs = params['cs']
        if '/QRP' in self.cs:
            self.cs = self.cs.replace('/QRP', '')
            self.qrp = True
        else:
            self.qrp = False
        self.de = params['de']
        self.lotw = self.cs in lotwData

        txt = self.text.lower()
        if 'ncdxf' in txt or 'beacon' in txt or 'bcn' in txt or '/B' in self.cs:
            self.isBeacon = True
            return

        self.band = params['band'] if params.has_key('band') else None
        self.mode = None
        self.subMode = None
        if params.has_key('mode') and params['mode']:
            self.setMode(params['mode'])
            if not self.mode:
                print params['mode']
                self.mode = params['mode']
        else:
            self.mode = None
        if params.has_key('subMode'):
            self.subMode = params['subMode']
        self.detectAwardsList = params['detectAwards'] \
                if params.has_key( 'detectAwards' ) else None

        if not self.band and self.freq:
            self.band = findDiap(DX.bands, self.freq)
            if not self.band:
                return

        if not self.mode and self.text:
            t = self.text.upper()
            for (mode, aliases) in DX.modes.iteritems():
                for alias in aliases:
                    if re.search('(^|\s)' + alias + '(\d|\s|$)', t):
                        self.setMode(alias)
                        break
        if not self.mode and self.freq:
            modeByMap = findDiap(DX.modesMap, self.freq)
            if modeByMap:
                if modeByMap == 'BCN':
                    self.isBeacon = True
                    return
                self.setMode(modeByMap)
        self.qrzData = False
        self.inDB = False

        if params.has_key('ts'):
            self.inDB = True
            self.ts = params['ts']
            self.time = params['time']
            self._district = params['district'] if params.has_key( 'state' ) \
                    else None
            self.region = params['region'] if params.has_key( 'region' ) \
                    else None
            self.gridsquare = params['gridsquare'] if params.has_key( 'qth' ) \
                    else None
            self.awards = params['awards'] if params.has_key('awards') else {}
            self.iota = params['iota'] if params.has_key('iota') else None

        else:

            self.time = params['time'][:2] + ':' + params['time'][2:4]
            self.ts = time.time()
            self.region = None
            self.district = None
            self.gridsquare = None

        dxCty = None
        pfx = None

        slashPos = self.cs.find('/')
        if self.cs.endswith( '/AM' ) or self.cs.endswith( '/MM' ) \
                or self.subMode == 'PSK125':
            return
        if slashPos != -1:
            parts = self.cs.split('/')
            for part in parts:
                if part in ('M', 'P', 'QRP', 'QRO'):
                    continue
                if prefixes[0].has_key(part):
                    pfx = part
                else:
                    m = DX.reTempPfx.search(part)
                    if m and prefixes[0].has_key(m.group(1)):
                        pfx = m.group(1)
                if pfx:
                    dxCty = prefixes[0][pfx]
                    break

        if not pfx:
            if prefixes[1].has_key(self.cs):
                dxCty = prefixes[1][self.cs]
            else:
                for c in xrange(1, len(self.cs)):
                    if prefixes[0].has_key(self.cs[:c]):
                        pfx = self.cs[:c]
                        dxCty = prefixes[0][self.cs[:c]]

        if dxCty and pfx:
            self.country = countries[ dxCty ] if countries.has_key( dxCty ) \
                    else None
            if pfx in DX.specialPfx:
                self.special = True
            elif self.country == 'Russia':
                m = DX.reDigitsSpecial.search(self.cs)
                if m:
                    self.special = True
            else:
                m = DX.reDigitsSpecial.search(pfx)
                if m:
                    self.special = True
                else:
                    m = DX.reDigitsSpecial.search(self.cs[len(pfx):])
                    if m:
                        self.special = True
                    else:
                        m = DX.reLettersSpecial.search(self.cs)
                        if m:
                            self.special = True
        self.pfx = dxCty

        if not self.inDB:

            csLookup = dxdb.getObject( 'callsigns', { 'callsign': self.cs }, \
                    False, True )

            if csLookup:
                self.inDB = True
                self.region = csLookup['region']
                self._district = csLookup['district']
                self.gridsquare = csLookup['qth']
                self.qrzData = csLookup['qrz_data_loaded']
                awLookup = cursor2dicts(
                    dxdb.execute(
                        """ 
                    select award, value, mode
                    from awards
                    where callsign = %s""", (self.cs, )), True)
                if awLookup:
                    for i in awLookup:
                        #if not i['mode']:
                        award = findAward(i['award'])
                        i['mode'] = self.getAwardMode(award)
                        self.awards[i['award']] = \
                            { 'value': i['value'], 'mode': i['mode'] }

            if '#' in self.de:
                self.text = (self.text.split(' ', 1))[0]
            self.testLookups()
            self.detectAwards()
            self.updateDB()

            if newSpot:
                dxdb.getObject( 'spots', \
                    { 'callsign': self.cs, 'time': self.time, \
                    'de': self.de, 'text': self.text, \
                    'freq': self.freq, 'band': self.band, \
                    'mode': self.mode, 'submode': self.subMode, \
                    'qrp': self.qrp, 'pfx': self.pfx }, \
                    True )
Ejemplo n.º 7
0
conf = siteConf()
webRoot = conf.get( 'web', 'root' ) 
dir = webRoot + ( '/debug' if args['t'] else '' )


def getSplitLine( file, fr = 0, to = None ):
    line = file.readline()
    if line:
        data = [item.strip( '"\r\n ' ) for item in line.split( ';' )]
        if to:
            return data[fr:to]
        else:
            return data[fr:]
    else:
        return None

columns = { 'callsign' : 0, 'region': 3, 'qth': 4 }

with open( webRoot + '/csv/i_callbook.csv', 'r' ) as file:
    params = { 'country': 'Italy' }
    data = getSplitLine( file )
    while data:
        for ( field, column ) in columns.iteritems():
            params[field] = data[column]
        dxdb.getObject( 'callsigns', params, True )
        data = getSplitLine( file )
    dxdb.commit()



Ejemplo n.º 8
0
args = vars(argparser.parse_args())

conf = siteConf()
webRoot = conf.get('web', 'root')
dir = webRoot + ('/debug' if args['t'] else '')


def getSplitLine(file, fr=0, to=None):
    line = file.readline()
    if line:
        data = [item.strip('"\r\n ') for item in line.split(';')]
        if to:
            return data[fr:to]
        else:
            return data[fr:]
    else:
        return None


columns = {'callsign': 0, 'region': 3, 'qth': 4}

with open(webRoot + '/csv/i_callbook.csv', 'r') as file:
    params = {'country': 'Italy'}
    data = getSplitLine(file)
    while data:
        for (field, column) in columns.iteritems():
            params[field] = data[column]
        dxdb.getObject('callsigns', params, True)
        data = getSplitLine(file)
    dxdb.commit()