<s> """<STR_LIT>""" <EOL> import argparse <EOL> import json <EOL> import time <EOL> from googleapiclient import discovery <EOL> from googleapiclient . http import MediaFileUpload <EOL> from oauth2client . client import GoogleCredentials <EOL> def load_data ( schema_path , data_path , project_id , dataset_id , table_id ) : <EOL> """<STR_LIT>""" <EOL> credentials = GoogleCredentials . get_application_default ( ) <EOL> bigquery = discovery . build ( '<STR_LIT>' , '<STR_LIT>' , credentials = credentials ) <EOL> source_format = '<STR_LIT>' <EOL> if data_path [ - <NUM_LIT:5> : ] . lower ( ) == '<STR_LIT>' : <EOL> source_format = '<STR_LIT>' <EOL> insert_request = bigquery . jobs ( ) . insert ( <EOL> projectId = project_id , <EOL> body = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : json . load ( open ( schema_path , '<STR_LIT:r>' ) ) <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : project_id , <EOL> '<STR_LIT>' : dataset_id , <EOL> '<STR_LIT>' : table_id <EOL> } , <EOL> '<STR_LIT>' : source_format , <EOL> } <EOL> } <EOL> } , <EOL> media_body = MediaFileUpload ( <EOL> data_path , <EOL> mimetype = '<STR_LIT>' ) ) <EOL> job = insert_request . execute ( ) <EOL> print ( '<STR_LIT>' ) <EOL> status_request = bigquery . jobs ( ) . get ( <EOL> projectId = job [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> jobId = job [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> while True : <EOL> result = status_request . execute ( num_retries = <NUM_LIT:2> ) <EOL> if result [ '<STR_LIT:status>' ] [ '<STR_LIT:state>' ] == '<STR_LIT>' : <EOL> if result [ '<STR_LIT:status>' ] . get ( '<STR_LIT>' ) : <EOL> raise RuntimeError ( '<STR_LIT:\n>' . join ( <EOL> e [ '<STR_LIT:message>' ] for e in result [ '<STR_LIT:status>' ] [ '<STR_LIT>' ] ) ) <EOL> print ( '<STR_LIT>' ) <EOL> return <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> def main ( project_id , dataset_id , table_name , schema_path , data_path ) : <EOL> load_data ( <EOL> schema_path , <EOL> data_path , <EOL> project_id , <EOL> dataset_id , <EOL> table_name ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parser = argparse . ArgumentParser ( <EOL> description = __doc__ , <EOL> formatter_class = argparse . RawDescriptionHelpFormatter ) <EOL> parser . add_argument ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> main ( <EOL> args . project_id , <EOL> args . dataset_id , <EOL> args . table_name , <EOL> args . schema_file , <EOL> args . data_file ) </s>
