Ejemplo n.º 1
0
 def updateAward(self, ad, av):
     if not self.inDB:
         self.updateDB()
     awardEntry = {'value': av, 'mode': self.getAwardMode(ad)}
     if not self.awards.has_key( ad['name'] ) or \
         self.awards[ad['name']] != awardEntry:
         if not self.offDB and not (ad.has_key('off_db') and ad['off_db']):
             idParams = {'callsign': self.cs, 'award': ad['name']}
             dxdb.paramUpdateInsert('awards', idParams, awardEntry)
             dxdb.commit()
         self.awards[ad['name']] = awardEntry
Ejemplo n.º 2
0
def joinModes( mode, modeAliases, awardsList = None ):
    sql = """
        select distinct callsign, award, value, band
        from user_awards where mode in """ + modeAliases
    if awardsList:
        sql += " and award in " + awardsList
    awardItems = cursor2dicts( dxdb.execute( sql ) )
    if awardItems:
        if isinstance( awardItems, dict ):
            awardItems = ( awardItems, )
        for awardItem in awardItems:
            award = [ x for x in awards if x['name'] == awardItem['award'] ][0]
            cfmTypes = [ 'cfm_paper', 'cfm_eqsl', 'cfm_lotw' ]
            if award.has_key( 'cfmTypes' ):
                cfmTypes = []
                for cfmType in award['cfmTypes']:
                    cfmTypes.append( cfmType[1] )
            sql = """select * from user_awards 
                where callsign = %(callsign)s and award = %(award)s 
                    and value = %(value)s and band = %(band)s and ( mode = '""" \
                    + mode + "' or mode in" + modeAliases + ")"
            modeItems = cursor2dicts( dxdb.execute( sql, awardItem ) )
            if isinstance(modeItems, dict):
                modeItems = ( modeItems, )
            awardItem['cfm'] = {}
            for cfmType in cfmTypes:
                awardItem['cfm'][cfmType] = False
            awardItem['worked_cs'] = ''
            awardItem['mode'] = mode
            for modeItem in modeItems:
                for cfmType in cfmTypes:
                    if cfmType in modeItem['cfm']:
                        awardItem['cfm'][cfmType] |= modeItem['cfm'][cfmType]
                if not ',' in awardItem['worked_cs'] and modeItem['worked_cs']:
                    if len( awardItem['worked_cs'] ) == 0:
                        awardItem['worked_cs'] = modeItem['worked_cs']
                    else:
                        awardItem['worked_cs'] += ', ' + modeItem['worked_cs']
            dxdb.paramUpdateInsert( 'user_awards', \
                spliceParams( awardItem, ( 'callsign', 'award', 'value', 'band', 'mode' ) ),
                spliceParams( awardItem, ( 'cfm', 'worked_cs' ) ) )
    sql = """delete from user_awards where mode in""" + modeAliases
    dxdb.execute( sql )
Ejemplo n.º 3
0
def loadAdif(callsign, adif, awardsEnabled):
    logging.debug('ADIF parsing start. Callsign: ' + callsign)
    idParams = {'callsign': callsign}
    updParams = {}
    for (award, enabled) in awardsEnabled.iteritems():
        idParams['award'] = award
        updParams['adif'] = enabled
        dxdb.paramUpdateInsert('users_awards_settings', idParams, updParams)
    awards = {}
    detectAwardsList = [x for x in awardsEnabled.keys() if awardsEnabled[x]]
    dxMod.dxdb = dxdb
    adif = adif.upper().replace('\r', '').replace('\n', '')
    if '<EOH>' in adif:
        adif = adif.split('<EOH>')[1]
    lines = adif.split('<EOR>')
    reDistrict = re.compile('[a-zA-Z]{2}-\d\d')
    lastLine = ''
    cfmFields = { 'cfm_paper': 'QSL_RCVD',\
        'cfm_eqsl': 'EQSL_QSL_RCVD',\
        'cfm_lotw': 'LOTW_QSL_RCVD' }
    for line in lines:
        if '<' in line:
            cs = getAdifField(line, 'CALL')
            lastLine = getAdifField( line, 'QSO_DATE' ) + ' ' + \
                    getAdifField( line, 'TIME_ON' ) + ' ' + cs
            freq = getAdifField(line, 'FREQ').replace('-',
                                                      '.').replace(':', '.')
            mode = getAdifField(line, 'MODE')
            iota = getAdifField(line, 'IOTA')


            dx = dxMod.DX( cs = cs, de = '', text = '', \
                    freq = float( freq ) * 1000 if freq else None, \
                    mode = mode if mode else None, \
                    iota = iota if iota else None, \
                    time = '    ', detectAwardsList = detectAwardsList )

            if dx.isBeacon:
                continue
            band = dx.band
            bandData = getAdifField(line, 'BAND').upper()
            if bands.has_key(bandData):
                band = bands[bandData]
            if band == None:
                logging.debug('No band: ' + line)
            if dx.country == 'Russia' or dx.country == 'Ukraine':
                district = getAdifField(line, 'CNTY')
                if not district or not reDistrict.match(district):
                    district = getAdifField(line, 'STATE')
                    if district and not reDistrict.match(district):
                        state = None
                if district and district != dx.district:
                    dx.offDB = True
                    dx.district = district
                    dx.detectAwards()
            if dx.country == 'USA':
                data = getAdifField(line, 'CNTY')
                if data and ',' in data:
                    region, district = data.split(',', 1)
                    district = district.title()
                    if ' Jd' in district:
                        district.replace(' Jd', ' JD')
                    district = region + ' ' + district
                    if region and district:
                        if region != dx.region or district != dx.district:
                            dx.offDB = True
                            dx.region = region
                            dx.district = district
                            dx.detectAwards()
            if dx.awards:
                cfm = {}
                for (cfmType, field) in cfmFields.iteritems():
                    cfm[cfmType] = getAdifField(line, field) == 'Y'
                for (award, value) in dx.awards.iteritems():
                    if awardsData[award].has_key( 'noStats' ) and \
                        awardsData[award]['noStats']:
                        continue
                    if not awards.has_key(award):
                        awards[award] = {}
                    if not awards[award].has_key(value['value']):
                        awards[award][value['value']] = {}
                    aw = awards[award][value['value']]
                    if awardsData[award].has_key('byBand') and \
                            awardsData[award]['byBand']:
                        if not band:
                            continue
                        if not aw.has_key(band):
                            aw[band] = {}
                        if not aw[band].has_key(value['mode']):
                            aw[band][value['mode']] = {}
                        aw = aw[band][value['mode']]
                    for cfmType in cfmFields.keys():
                        if not aw.has_key(cfmType):
                            aw[cfmType] = False
                        if not aw[cfmType] and cfm[cfmType]:
                            aw[cfmType] = True
                    if not aw.has_key('callsigns'):
                        aw['callsigns'] = []
                    if len( aw['callsigns'] ) < 2 and \
                        not cs in aw['callsigns']:
                        aw['callsigns'].append(cs)
    logging.debug('ADIF parsed')
    commitFl = False
    if awards:

        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

        for award in awards.keys():
            for value in awards[award].keys():
                awState = awards[award][value]
                idParams = { 'callsign': callsign, \
                        'award': award,\
                        'value': value, \
                        'band': 'N/A', \
                        'mode': 'N/A' }
                cfmTypes = None
                if awardsData[award].has_key('cfmTypes'):
                    cfmTypes = [
                        type[1] for type in awardsData[award]['cfmTypes']
                    ]
                if awardsData[award].has_key('byBand') and \
                    awardsData[award]['byBand']:
                    for band in awState:
                        idParams['band'] = band
                        for mode in awState[band]:
                            idParams['mode'] = mode
                            commitFl = updateAward( idParams, \
                                    awState[band][mode], cfmTypes )
                else:
                    commitFl = updateAward(idParams, awState, cfmTypes)

    msg = { 'text': 'Your ADIF log was processed succefully.' + \
            ( '' if commitFl \
                else ' No new callsigns for supported awards were found.' ), \
            'reload': commitFl }

    dxdb.updateObject( 'users', \
            { 'callsign': callsign, 'last_adif_line': lastLine, \
            'msg': json.dumps( msg ) }, \
            'callsign' )
    dxdb.commit()

    return (commitFl, lastLine)
Ejemplo n.º 4
0
def loadAdif( callsign, adif, awardsEnabled ):
    logging.debug( 'ADIF parsing start. Callsign: ' + callsign )
    idParams = { 'callsign': callsign }
    updParams = {}
    for ( award, enabled ) in awardsEnabled.iteritems():
        idParams['award'] = award
        updParams['adif'] = enabled
        dxdb.paramUpdateInsert( 'users_awards_settings', idParams, updParams )
    awards = {}
    detectAwardsList = [ x for x in awardsEnabled.keys() if awardsEnabled[x] ]
    dxMod.dxdb = dxdb
    adif = adif.upper().replace( '\r', '' ).replace( '\n', '' )
    if '<EOH>' in adif:
        adif = adif.split( '<EOH>' )[1]
    lines = adif.split( '<EOR>' )
    reDistrict = re.compile( '[a-zA-Z]{2}-\d\d' )
    lastLine = ''
    cfmFields = { 'cfm_paper': 'QSL_RCVD',\
        'cfm_eqsl': 'EQSL_QSL_RCVD',\
        'cfm_lotw': 'LOTW_QSL_RCVD' }
    for line in lines:
        if '<' in line:
            cs = getAdifField( line, 'CALL' )  
            lastLine = getAdifField( line, 'QSO_DATE' ) + ' ' + \
                    getAdifField( line, 'TIME_ON' ) + ' ' + cs
            freq = getAdifField( line, 'FREQ' ).replace( '-', '.' ).replace( ':', '.' )
            mode = getAdifField( line, 'MODE' )
            iota = getAdifField( line, 'IOTA' )


            dx = dxMod.DX( cs = cs, de = '', text = '', \
                    freq = float( freq ) * 1000 if freq else None, \
                    mode = mode if mode else None, \
                    iota = iota if iota else None, \
                    time = '    ', detectAwardsList = detectAwardsList )


            if dx.isBeacon:
                continue
            band = dx.band
            bandData = getAdifField( line, 'BAND' ).upper()
            if bands.has_key( bandData ):
                band = bands[bandData]
            if band == None:
                logging.debug( 'No band: ' + line )
            if dx.country == 'Russia' or dx.country == 'Ukraine':
                district = getAdifField( line, 'CNTY' )
                if not district or not reDistrict.match( district ):
                    district = getAdifField( line, 'STATE' )
                    if district and not reDistrict.match( district ):
                        state = None
                if district and district != dx.district:
                    dx.offDB = True
                    dx.district = district
                    dx.detectAwards()
            if dx.country == 'USA':
                data = getAdifField( line, 'CNTY'  )
                if data and ',' in data:
                    region, district = data.split( ',', 1 )
                    district = district.title()
                    if ' Jd' in  district:
                        district.replace( ' Jd', ' JD' )
                    district = region + ' ' + district
                    if region and district:
                        if region != dx.region or district != dx.district:
                            dx.offDB = True
                            dx.region = region
                            dx.district = district
                            dx.detectAwards()
            if dx.awards:
                cfm = {}
                for ( cfmType, field ) in cfmFields.iteritems():
                    cfm[cfmType] = getAdifField( line, field ) == 'Y'
                for ( award, value ) in dx.awards.iteritems():
                    if awardsData[award].has_key( 'noStats' ) and \
                        awardsData[award]['noStats']:
                        continue
                    if not awards.has_key(award):
                        awards[award] = {}
                    if not awards[award].has_key( value['value'] ):
                        awards[award][ value['value'] ] = {}
                    aw = awards[award][ value['value'] ]
                    if awardsData[award].has_key('byBand') and \
                            awardsData[award]['byBand']:
                        if not band:
                            continue
                        if not aw.has_key( band ):
                            aw[band] = {}
                        if not aw[band].has_key( value['mode'] ):
                            aw[band][value['mode']] = {}
                        aw = aw[band][value['mode']]
                    for cfmType in cfmFields.keys():
                        if not aw.has_key( cfmType ):
                            aw[cfmType] = False
                        if not aw[cfmType] and cfm[cfmType]:
                            aw[cfmType] = True
                    if not aw.has_key( 'callsigns' ):
                        aw['callsigns'] = []
                    if len( aw['callsigns'] ) < 2 and \
                        not cs in aw['callsigns']:
                        aw['callsigns'].append( cs )
    logging.debug( 'ADIF parsed' )
    commitFl = False
    if awards:

        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

        for award in awards.keys():
            for value in awards[award].keys():
                awState = awards[award][value]
                idParams = { 'callsign': callsign, \
                        'award': award,\
                        'value': value, \
                        'band': 'N/A', \
                        'mode': 'N/A' }
                cfmTypes = None
                if awardsData[award].has_key( 'cfmTypes' ):
                    cfmTypes = [ type[1] for type in awardsData[award]['cfmTypes'] ]
                if awardsData[award].has_key('byBand') and \
                    awardsData[award]['byBand']:
                    for band in awState:
                        idParams['band'] = band
                        for mode in awState[band]:
                            idParams['mode'] = mode
                            commitFl = updateAward( idParams, \
                                    awState[band][mode], cfmTypes )
                else:
                    commitFl = updateAward( idParams, awState, cfmTypes )

    msg = { 'text': 'Your ADIF log was processed succefully.' + \
            ( '' if commitFl \
                else ' No new callsigns for supported awards were found.' ), \
            'reload': commitFl }

    dxdb.updateObject( 'users', \
            { 'callsign': callsign, 'last_adif_line': lastLine, \
            'msg': json.dumps( msg ) }, \
            'callsign' )
    dxdb.commit()

    return ( commitFl, lastLine )
Ejemplo n.º 5
0
webRoot = conf.get( 'web', ( 'test_' if args['t'] else '' ) + 'root' ) 

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 = { 'id': { 'callsign' : 0 }, 'upd':  { 'district': 1 } }

with open( webRoot + '/csv/dl_callbook.csv', 'r' ) as file:
    params = { 'id': {}, 'upd': { 'country': 'Germany' } }
    data = getSplitLine( file )
    while data:
        for type in columns:
            for ( field, column ) in columns[type].iteritems():
                params[type][field] = data[column]

        dxdb.paramUpdateInsert( 'callsigns', params['id'], params['upd'] )

        data = getSplitLine( file )
    dxdb.commit()



Ejemplo n.º 6
0
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 uwsgisrv import spliceParams

data = { 'callsign': '1111' }
idParams = { 'callsign': data['callsign'] }
if data.has_key('delete'):
    if dxdb.paramDelete( 'dxpedition', idParams ):
        okResponse = 'OK'
    else:
        dbError = True
else:
    updParams = spliceParams( data, [ 'dt_begin', 'dt_end', \
        'descr', 'link' ] )
    if dxdb.paramUpdateInsert( 'dxpedition', idParams, \
            updParams ):
        okResponse = 'OK'
    else:
        dbError = True
if okResponse:
    dxdb.commit()