Advertisement
RoknerTest

Untitled

Apr 3rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import requests
  2. import validators
  3. import settings
  4.  
  5. _user_key = None
  6.  
  7. def login_user(username, password):
  8. global _user_key
  9. data = {
  10. 'api_dev_key': settings.PASTEBIN_API_KEY,
  11. 'api_user_name': username,
  12. 'api_user_password': password
  13. }
  14. resp = requests.post(settings.PASTEBIN_USER_LOGIN_URL, data)
  15. result = {
  16. 'data': resp.text,
  17. 'success': True
  18. }
  19. if result['data'].lower().startswith('bad'):
  20. result['success'] = False
  21. else:
  22. _user_key = result['data']
  23.  
  24. return result
  25.  
  26. def paste_create(content, title, syntax, expiry):
  27. data = {
  28. 'api_dev_key': settings.PASTEBIN_API_KEY,
  29. 'api_option': settings.PASTEBIN_API_PASTE_OPTION,
  30. 'api_paste_code': content,
  31. }
  32. if title:
  33. data['api_paste_name'] = title
  34. if syntax:
  35. data['api_paste_format'] = title
  36. if title:
  37. data['api_paste_expire_date'] = expiry
  38.  
  39. if _user_key:
  40. data['api_user_key'] = _user_key
  41. resp = requests.post(settings.PASTEBIN_CREATE_URL, data)
  42. result = {
  43. 'data': resp.text,
  44. 'success': True
  45. }
  46. if not validators.url(result['data']):
  47. result['success'] = False
  48.  
  49. return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement