Advertisement
DeaD_EyE

pastebin_for_cell_magic

Apr 23rd, 2019
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import json
  2. from getpass import getpass
  3. from pathlib import Path
  4. from pbwrap import Pastebin
  5. # https://github.com/Mikts/pbwrap
  6.  
  7.  
  8. def paste_python(code, title=None):
  9.     return pastebin.create_paste(code, api_paste_name=title, api_paste_format='python')
  10.  
  11.  
  12. def get_creds():
  13.     creds = Path.home() / '.pastebin-secret.json'
  14.     if not creds.exists():
  15.         api_dev_key = input('DEV Key: ')
  16.         username = input('User Name: ')
  17.         password = getpass()
  18.         pb = Pastebin(api_dev_key)
  19.         api_user_key = pb.authenticate(username, password)
  20.         creds.write_text(json.dumps({'api_dev_key': api_dev_key, 'api_user_key': api_user_key}))
  21.     else:
  22.         secret = json.loads(creds.read_text())
  23.         pb = Pastebin(secret['api_dev_key'])
  24.         pb.api_user_key = secret['api_user_key']
  25.     return pb
  26.  
  27.  
  28. pastebin = get_creds()
  29. #code = input('Code to paste: ')
  30. #title = input('Title: ')
  31. #url = paste_python(code, title)
  32. #print(url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement