Пример #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
Пример #2
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()
Пример #3
0
 def district(self, value):
     v = None
     if self.country == 'USA':
         v = value
         if v and self.region == None:
             r = v.split(' ')[0]
             if r in fieldValues['USA']['region']:
                 self.region = r
                 self.updateDB()
     elif self.country in ('Japan', 'Germany', 'Poland', 'France'):
         v = value
     else:
         if value:
             v = value.replace(' ', '')
             if self.country in ('Russia', 'Ukraine'):
                 m = DX.reState0.match(v)
                 if m:
                     v = m.group(1) + '-' + m.group(2)
     if v and fieldValues.has_key( self.country ) and \
         fieldValuesSubst[ self.country ].has_key( 'district' ) and \
         fieldValuesSubst[ self.country ]['district'].has_key( v ):
         v = fieldValuesSubst[self.country]['district'][v]
     elif v and fieldValues.has_key( self.country) \
         and fieldValues[ self.country ].has_key( 'district' ) and \
         not v in fieldValues[ self.country ]['district']:
         return
     if self._district and self._district != v and self.awards:
         self.awards.clear()
         dxdb.execute(
             """
             delete from awards
             where callsign = %s """, (self.cs, ))
         dxdb.commit()
     if self._district != v:
         self._district = v
         self.updateDB()
Пример #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)
Пример #5
0
for aw in awards:
    if not aw.has_key( 'byBand' ) or not aw['byBand']:
        continue
    modes = aw['modes'] if aw.has_key( 'modes' ) else allModes
    modesStr = makeStr( modes )
    if 'DIGI' in modes:
        sql = """insert into user_awards 
            ( callsign, award, value, cfm_paper, cfm_lotw, cfm_eqsl, mode, band )
            select callsign, award, value, bool_or( cfm_paper ), bool_or( cfm_lotw ),
                bool_or( cfm_eqsl ), 'DIGI', band
            from user_awards
            where award = %s and mode in (""" + digiModesStr + ") " + \
            ( " and callsign = 'QQQQ' " if testMode else '' ) + \
            """group by callsign, award, value, band"""
        dxdb.execute( sql, ( aw['name'], ) )
        dxdb.commit()
    sql = """delete from user_awards
        where award = %s and not mode in (""" + modesStr + """) and 
        mode != 'N/A' """ + \
        ( "and callsign = 'QQQQ' " if testMode else '' )
    dxdb.execute( sql, ( aw['name'], ) )
    dxdb.commit()


with open( webRoot + '/userMetadata.json', 'w' ) as f:
    f.write( json.dumps( udv ) )



Пример #6
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 )
Пример #7
0
    awardCfm = [ type[1] for type in aw['cfmTypes'] ] if aw.has_key( 'cfmTypes' ) \
            else cfmTypesDef

    data = cursor2dicts(  dxdb.execute( sql, ( aw['name'], ) ), False )
    if data:
        for record in data:
            recordCfm = { cfmType: record[cfmType] if record.has_key( cfmType ) \
                            else False for cfmType in awardCfm }
            dxdb.paramUpdate( 'user_awards', \
                    { 'award': aw['name'], 'value': record['value'], \
                    'band': record['band'], 'mode': record['mode'], \
                    'callsign': record['callsign'] },
                    { 'cfm': json.dumps( recordCfm ) } )
            if not record['callsign'] in users:
                users.append( record['callsign'] )
dxdb.commit()
umdPath = webRoot + '/userMetadata.json'
umd = loadJSON( umdPath  )
if not umd:
    umd = {}
ts = time.time()
for callsign in users:
    umd[callsign] = ts
with open( umdPath, 'w' ) as f:
    f.write( json.dumps( umd ) )



#with open( webRoot + '/userMetadata.json', 'w' ) as f:
#    f.write( json.dumps( udv ) )