<s> """<STR_LIT>""" <EOL> from googleads import dfp <EOL> def main ( client ) : <EOL> inventory_service = client . GetService ( '<STR_LIT>' , version = '<STR_LIT>' ) <EOL> statement = dfp . FilterStatement ( ) <EOL> all_ad_units = [ ] <EOL> while True : <EOL> response = inventory_service . getAdUnitsByStatement ( <EOL> statement . ToStatement ( ) ) <EOL> if '<STR_LIT>' in response : <EOL> all_ad_units . extend ( response [ '<STR_LIT>' ] ) <EOL> statement . offset += dfp . SUGGESTED_PAGE_LIMIT <EOL> else : <EOL> break <EOL> query = '<STR_LIT>' <EOL> root_statement = dfp . FilterStatement ( query ) <EOL> response = inventory_service . getAdUnitsByStatement ( <EOL> root_statement . ToStatement ( ) ) <EOL> root_ad_unit = response [ '<STR_LIT>' ] <EOL> if root_ad_unit : <EOL> BuildAndDisplayAdUnitTree ( root_ad_unit , all_ad_units ) <EOL> else : <EOL> print '<STR_LIT>' <EOL> def DisplayAdUnitTree ( root_ad_unit , ad_unit_tree , depth = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT>' % ( GenerateTab ( depth ) , root_ad_unit [ '<STR_LIT:name>' ] , <EOL> root_ad_unit [ '<STR_LIT:id>' ] ) <EOL> if root_ad_unit [ '<STR_LIT:id>' ] in ad_unit_tree : <EOL> for child in ad_unit_tree [ root_ad_unit [ '<STR_LIT:id>' ] ] : <EOL> DisplayAdUnitTree ( child , ad_unit_tree , depth + <NUM_LIT:1> ) <EOL> def GenerateTab ( depth ) : <EOL> """<STR_LIT>""" <EOL> tab_list = [ ] <EOL> if depth > <NUM_LIT:0> : <EOL> tab_list . append ( '<STR_LIT:U+0020>' ) <EOL> tab_list . append ( '<STR_LIT>' * depth ) <EOL> tab_list . append ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . join ( tab_list ) <EOL> def BuildAndDisplayAdUnitTree ( root_ad_unit , all_ad_units ) : <EOL> """<STR_LIT>""" <EOL> tree = { } <EOL> for ad_unit in all_ad_units : <EOL> if '<STR_LIT>' in ad_unit : <EOL> if ad_unit [ '<STR_LIT>' ] not in tree : <EOL> tree [ ad_unit [ '<STR_LIT>' ] ] = [ ] <EOL> tree [ ad_unit [ '<STR_LIT>' ] ] . append ( ad_unit ) <EOL> DisplayAdUnitTree ( root_ad_unit , tree ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> dfp_client = dfp . DfpClient . LoadFromStorage ( ) <EOL> main ( dfp_client ) </s>
