def main(): test = MonthData( 2 , 2012 ) assert len( test.data ) == 30 test = MonthData( 2 , 2013 ) assert len( test.data ) == 29 test = MonthData( 3 , 2014 ) assert len( test.data ) == 32 test = MonthData( 4 , 2014 ) assert len( test.data ) == 31 #test = MonthData( 8 , 2015 ) #PriceWriter.write_month_data_to_file( test , "test" ) #test = PriceReader.read_month_data( 8 , 2015 , "test" ) #print test #Mithril ore priceData = PriceCrawler.get_price_data_from_html( 447 ) PriceWriter.save_data( priceData ) #Mithril bar priceData = PriceCrawler.get_price_data_from_html( 2359 ) PriceWriter.save_data( priceData ) priceData = PriceCrawler.get_price_data_from_json( "Mithril bar" , 2359 ) PriceWriter.save_data( priceData ) #404 Error priceData = PriceCrawler.get_price_data_from_html( 21736 ) assert( priceData == None ) fromCSV = PriceReader.get_price_data_from_csv( 447 ) fromHTML = PriceCrawler.get_price_data_from_html( 447 ) assert fromCSV == fromHTML print "Regression testing for price_data_io.py passed."
def download_data_by_id( id ): priceData = PriceCrawler.get_price_data_from_html( id ) if ( priceData != None ): f = open( "price_data/item_ids" , "a" ) f.write( priceData.get_name() + "," + str( id ) + "\n" ) f.close() PriceWriter.write_price_data_to_csv( "price_data/master_list/" + str(id) + ".csv" , priceData )
def record_commodity_stats(startId, endId): for i in range(startId, endId): print "Processing " + str(i) testData = PriceCrawler.get_price_data_from_html(i) if (not testData is None): maxPrice = 0 minPrice = 999999999 maxVolume = 0 minVolume = 999999999 allPoints = testData.get_all_datapoints() #we do not include the last data point because #that is today's data, which may be incomplete #and so the volume may be much less than what it #really is. for datapoint in allPoints[1:len(allPoints) - 1]: #prices and volumes of 0 are invalid if (datapoint.get_price != 0): maxPrice = max(datapoint.get_price(), maxPrice) minPrice = min(datapoint.get_price(), minPrice) if (datapoint.get_volume() != 0): maxVolume = max(datapoint.get_volume(), maxVolume) minVolume = min(datapoint.get_volume(), minVolume) out = open("price_data/item_stats", "a") out.write( str(i) + "," + str(maxPrice) + "," + str(minPrice) + \ "," + str(maxVolume) + "," + str(minVolume) + "\n" ) out.close() else: print str(i) + " was not a valid id" #let's not get blocked for too many requests sleepInterval = randint(1, 2) sleepInterval = 2 print "Sleeping " + str(sleepInterval) sleep(sleepInterval)
def record_commodity_stats( startId , endId ): for i in range( startId , endId ): print "Processing " + str( i ) testData = PriceCrawler.get_price_data_from_html( i ) if ( not testData is None ): maxPrice = 0 minPrice = 999999999 maxVolume = 0 minVolume = 999999999 allPoints = testData.get_all_datapoints() #we do not include the last data point because #that is today's data, which may be incomplete #and so the volume may be much less than what it #really is. for datapoint in allPoints[1:len(allPoints)-1]: #prices and volumes of 0 are invalid if ( datapoint.get_price != 0 ): maxPrice = max( datapoint.get_price() , maxPrice ) minPrice = min( datapoint.get_price() , minPrice ) if ( datapoint.get_volume() != 0 ): maxVolume = max( datapoint.get_volume() , maxVolume ) minVolume = min( datapoint.get_volume() , minVolume ) out = open( "price_data/item_stats" , "a" ) out.write( str(i) + "," + str(maxPrice) + "," + str(minPrice) + \ "," + str(maxVolume) + "," + str(minVolume) + "\n" ) out.close() else: print str( i ) + " was not a valid id" #let's not get blocked for too many requests sleepInterval = randint( 1 , 2 ) sleepInterval = 2 print "Sleeping " + str( sleepInterval ) sleep( sleepInterval )