Guest User

Untitled

a guest
Jan 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import json,boto3
  2.  
  3. def notebook2py(nb_bucket,nb_key,py_bucket,py_key):
  4. s3c = boto3.client('s3')
  5. obj = s3c.get_object(Bucket=nb_bucket, Key=nb_key)
  6. content = json.loads(obj['Body'].read())
  7.  
  8. notebook_text = ['\n'+item['text'][8::] for item in content['paragraphs'] if 'enabled' in item['config'] and item['config']['enabled']==True and item['text'].startswith('%pyspark')]
  9.  
  10. io_handle = StringIO('\n'.join(notebook_text))
  11. s3c.put_object(Bucket=py_bucket, Key=py_key, Body=io_handle.read())
Add Comment
Please, Sign In to add comment