RoknerTest

Untitled

Apr 3rd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import fileinput
  2. import sys, getopt
  3. from pastebin_connection import paste_create, login_user
  4.  
  5.  
  6. def add_paste(content, succ, error):
  7. if content:
  8. result = paste_create(content)
  9. if result['success']:
  10. succ.append(result['data'])
  11. else:
  12. error.append(result['data'])
  13. paste_content = ""
  14.  
  15. def handle_input(args):
  16. paste_content = ""
  17. succ = []
  18. error = []
  19.  
  20. for line in fileinput.input(args):
  21. if fileinput.isfirstline():
  22. add_paste(paste_content, succ, error)
  23.  
  24. paste_content += line
  25.  
  26. add_paste(paste_content, succ, error)
  27. if succ:
  28. print("Succesful pastes")
  29. for url in succ:
  30. print(url)
  31.  
  32. print()
  33.  
  34. if error:
  35. print("Error")
  36. for url in error:
  37. print(url)
  38.  
  39. def print_help():
  40. print()
  41. print("Use like cat program to upload to pastebin.")
  42. print("[-u|--username] [-p|--password] - for username and assword")
  43. print()
  44. pass
  45.  
  46. def main(argv):
  47. username = ''
  48. password = ''
  49. try:
  50. opts, args = getopt.gnu_getopt(argv, 'hu:p:', ["username=", "password="])
  51. except getopt.GetoptError:
  52. print_help()
  53. sys.exit(2)
  54.  
  55. for opt, arg in opts:
  56. if opt == '-h':
  57. print_help()
  58. sys.exit()
  59. elif opt in ('-u', '--username'):
  60. username = arg
  61. elif opt in ('-p', '--password'):
  62. password = arg
  63.  
  64. if username and password:
  65. res = login_user(username, password)
  66. if res['success']:
  67. print('Successful login')
  68. else:
  69. print(res['data'])
  70.  
  71. handle_input(args)
  72.  
  73. if __name__ == "__main__":
  74. main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment