<s> from google . appengine . ext import db <EOL> import models . raw_report <EOL> import models . data <EOL> import re <EOL> import settings <EOL> import hashlib <EOL> from processors import report_munger <EOL> def persist ( filename , content ) : <EOL> p = re . compile ( '<STR_LIT>' ) <EOL> if p . match ( filename ) is None and filename . find ( '<STR_LIT>' ) == - <NUM_LIT:1> : <EOL> parsed_data = report_munger . AppStoreSalesDataMunger ( ) . munge ( content , settings . SETTINGS [ '<STR_LIT>' ] ) <EOL> date = parsed_data . keys ( ) [ - <NUM_LIT:1> ] <EOL> if persist_original_file ( filename , date , content ) != False : <EOL> persist_parsed_data ( parsed_data ) <EOL> def persist_original_file ( filename , date , content ) : <EOL> sha1 = hashlib . sha1 ( content ) . hexdigest ( ) <EOL> existing_report = db . GqlQuery ( "<STR_LIT>" , date , sha1 ) . get ( ) <EOL> if existing_report == None : <EOL> report = models . raw_report . RawReport ( ) <EOL> report . filename = filename <EOL> report . content = content <EOL> report . sha1 = sha1 <EOL> report . report_date = date <EOL> return report . put ( ) <EOL> else : <EOL> return False <EOL> def persist_parsed_data ( parsed_data ) : <EOL> date = parsed_data . keys ( ) [ - <NUM_LIT:1> ] <EOL> sales = parsed_data [ date ] [ '<STR_LIT>' ] <EOL> upgrades = parsed_data [ date ] [ '<STR_LIT>' ] <EOL> for product in sales : <EOL> sale_store = models . data . Sale ( ) <EOL> _store_data ( product , sale_store , date ) <EOL> sale_store . put ( ) <EOL> for product in upgrades : <EOL> upgrade_store = models . data . Upgrade ( ) <EOL> _store_data ( product , upgrade_store , date ) <EOL> upgrade_store . put ( ) <EOL> def _store_data ( product , store , date ) : <EOL> store . income_revenue = float ( product [ '<STR_LIT>' ] ) <EOL> store . income_units = product [ '<STR_LIT>' ] <EOL> store . revenue_by_currency = product [ '<STR_LIT>' ] <EOL> store . units_by_country = product [ '<STR_LIT>' ] <EOL> store . refund_loss = float ( product [ '<STR_LIT>' ] ) <EOL> store . refund_units = float ( product [ '<STR_LIT>' ] ) <EOL> store . pid = product [ '<STR_LIT>' ] <EOL> store . report_date = date </s>
