def process_url( service_name, url, database ): "process" soup = soupfy( url ) rows = soup.findAll( lambda tag : 'tr' == tag.name and tag.find( 'td' ) ) date = rows[ 0 ].td.string match = DATE_MATCH.match( date ) year = str( datetime.now().year ) month = match.group( 1 ) day = match.group( 2 ) data_date = '/'.join( [ year, month, day ] ) rows_days = rows[ 0 ].findAll( 'td' )[ 2 : ] swaps = rows[ 1 ].findAll( 'td', attrs = { 'class' : 'plus' } ) currencies = zip( CURRENCIES, zip( rows_days, swaps ) ) data = [] for currency, tags in currencies: days = int( tags[ 0 ].string ) if days: if 'ZARJPY' == currency: swapbuy = int( tags[ 1 ].string ) / 10 else: swapbuy = int( tags[ 1 ].string ) data.append( dict( data_date = data_date, service_name = service_name, currency = currency, days = days, swapbuy = swapbuy, ) ) update_currency( database, data )
def process_url( service_name, url, database ): "process" soup = soupfy( url ) data_date = soup.find( 'h2' ).string[ : 10 ] currencies = { 'US' : 'USDJPY', 'EU' : 'EURJPY', 'AU' : 'AUDJPY', 'UK' : 'GBPJPY', 'NZ' : 'NZDJPY', 'CA' : 'CADJPY', 'SW' : 'CHFJPY', 'HK' : 'HKDJPY', 'SA' : 'ZARJPY', } data = [] for alt, currency in currencies.iteritems(): row = soup.find( lambda tag: ( 'tr' == tag.name and tag.find( 'td' ) and tag.find( 'img', attrs = { 'alt' : alt } ) and tag.find( 'img', attrs = { 'src' : '../img/icon_kokki08.gif' } ) ) ) for index, service_name in [ ( 3, 'gaitame_dotcom_next' ), ]: match = YEN_MATCH.match( row.contents[ index ].string ) try: swapbuy = int( match.group( 1 ) ) data.append( dict( data_date = data_date, service_name = service_name, currency = currency, days = 1, swapbuy = swapbuy ) ) except: pass update_currency( database, data )
def process_url( service_name, url, database ): "process" soup = soupfy( url ) year = str( date.today().year ) tables = [ soup.find( 'div', attrs = { 'id' : 'div1' } ), soup.find( 'div', attrs = { 'id' : 'div2' } ) ] data = [] steps = { 0 : [ 'USDJPY', 'EURJPY', 'GBPJPY', 'AUDJPY', ], 1 : [ 'NZDJPY', 'CADJPY', 'CHFJPY', 'ZARJPY', ], } for index, currencies in steps.iteritems(): for row in tables[ index ].findAll( 'tr' ): try: match = DATE_MATCH.match( row.contents[ 1 ].nobr.string ) if match: month = match.group( 1 ) day = match.group( 2 ) else: raise for currency in currencies: indices = TABLE_INDEX[ currency ] try: days = days = int( row.contents[ indices[ 'days' ] ].string ) if days: data.append( dict( data_date = '/'.join( [ year, month, day ] ), service_name = service_name, currency = currency, days = days, swapbuy = int( row.contents[ indices[ 'swapbuy' ] ].string ), ) ) except: pass except: pass update_currency( database, data )
def process_url( service_name, url, database ): "process" soup = soupfy( url ) year = str( date.today().year ) trs = soup.findAll( 'tr' ) rows = [] i = 0 while True: try: rows.append( ( trs[ i ], trs[ i + 1 ], trs[ i + 2 ] ) ) i += 3 except: break data = [] for row in rows: for currency in [ 'USDJPY', 'EURJPY', 'AUDJPY', 'NZDJPY', 'GBPJPY', 'CHFJPY', 'CADJPY', 'ZARJPY', ]: try: days = int( row[ 0 ].contents[ TABLE_INDEX[ 'days' ][ currency ] ].contents[ 0 ] ) if days: data.append( dict( data_date = '/'.join( [ year, row[ 0 ].contents[ 1 ].contents[ 0 ].replace( ' ', '' ).replace( '\n', '' ) ] ), service_name = service_name, currency = currency, days = days, swapbuy = int( row[ 1 ].contents[ TABLE_INDEX[ 'swapbuy' ][ currency ] ].contents[ 0 ] ), ) ) except: pass update_currency( database, data )
def process_url( service_name, url, database ): "process" weekday = get_weekday() if 0 == weekday: days = 3 else: days = 1 soup = soupfy( url ) data = [] for currency in soup.findAll( 'swapdata' ): if currency.currencypairname.string in CURRENCIES: data.append( dict( data_date = currency.rollto.string, service_name = service_name, currency = currency.currencypairname.string, days = days, swapbuy = float( currency.swapbuy.string ) * 10000, ) ) update_currency( database, data )
def process_url( service_name, url, database ): "process" year = str( date.today().year ) soup = soupfy( url ) currencies = { 'USD/JPY' : 'USDJPY', 'EUR/JPY' : 'EURJPY', 'GBP/JPY' : 'GBPJPY', 'AUD/JPY' : 'AUDJPY', 'NZD/JPY' : 'NZDJPY', 'CAD/JPY' : 'CADJPY', 'CHF/JPY' : 'CHFJPY', 'SGD/JPY' : 'SGDJPY', 'NOK/JPY' : 'NOKJPY', 'SEK/JPY' : 'SEKJPY', 'HKD/JPY' : 'HKDJPY', 'ZAR/JPY' : 'ZARJPY', } data = [] for abbr, currency in currencies.iteritems(): row = soup.find( lambda tag: ( 'tr' == tag.name and tag.find( 'th', attrs = { 'scope' : 'row' } ) and abbr == tag.findAll( 'th', attrs = { 'scope' : 'row' } )[ 1 ].string ) ) try: data_date = row.findAll( 'td', attrs = { 'class' : 'date' } )[ 1 ].string days = row.find( 'td', attrs = { 'class' : 'swapDay' } ).string swapbuy = row.contents[ 13 ].span.string match = YEN_MATCH.match( swapbuy.string ) swapbuy = int( match.group( 1 ) ) data.append( dict( data_date = '/'.join( [ year, data_date ] ), service_name = service_name, currency = currency, days = int( days ), swapbuy = swapbuy ) ) except: pass update_currency( database, data )
def process_url( service_name, url, database ): "process" soup = soupfy( url ) date = soup.find( 'p', attrs = { 'class' : 'tableDate' } ).contents[ 0 ] match = DATE_MATCH.match( date ) year = match.group( 1 ) tables = soup.findAll( 'table' ) data = [] steps = { 0 : [ 'USDJPY', 'EURJPY', 'GBPJPY', 'AUDJPY', ], 1 : [ 'NZDJPY', 'CADJPY', 'ZARJPY', 'CHFJPY', ], } for index, currencies in steps.iteritems(): for row in tables[ index ].findAll( lambda tag: 'tr' == tag.name and tag.find( 'th', attrs = { 'class' : 'alignR' } ) ): for currency in currencies: indices = TABLE_INDEX[ currency ] try: days = int( row.contents[ indices[ 'days' ] ].string ) if days: data.append( dict( data_date = '/'.join( [ year, row.contents[ indices[ 'date' ] ].string ] ), service_name = service_name, currency = currency, days = days, swapbuy = int( row.contents[ indices[ 'swapbuy' ] ].span.string ), ) ) except: pass update_currency( database, data )