Advertisement
RoknerTest

Some Random Pastet

Apr 3rd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 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, title, syntax, expiry, succ, error):
  7. if content:
  8. result = paste_create(content, title, syntax, expiry)
  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, title, syntax, expiry):
  16. paste_content = ""
  17. succ = []
  18. error = []
  19.  
  20. for line in fileinput.input(args):
  21. if fileinput.isfirstline():
  22. add_paste(paste_content, title, syntax, expiry, succ, error)
  23.  
  24. paste_content += line
  25.  
  26. add_paste(paste_content, title, syntax, expiry, 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. syntax = ''
  50. expiry = ''
  51. clip = False
  52. try:
  53. opts, args = getopt.gnu_getopt(argv, 'hu:p:t:s:e:c', ["username=", "password=", "title=", "syntax=", "expiry="])
  54. except getopt.GetoptError:
  55. print_help()
  56. sys.exit(2)
  57.  
  58. for opt, arg in opts:
  59. if opt == '-h':
  60. print_help()
  61. sys.exit()
  62. elif opt in ('-u', '--username'):
  63. username = arg
  64. elif opt in ('-p', '--password'):
  65. password = arg
  66. elif opt in ('-t', '--title'):
  67. title = arg
  68. elif opt in ('-s', '--syntax'):
  69. syntax = arg
  70. elif opt in ('-e', '--expiry'):
  71. expiry = arg
  72. elif opt == '-c':
  73. clip = True
  74.  
  75. if username and password:
  76. res = login_user(username, password)
  77. if res['success']:
  78. print('Successful login')
  79. else:
  80. print(res['data'])
  81.  
  82. handle_input(args, title, syntax, expiry)
  83.  
  84. if __name__ == "__main__":
  85. main(sys.argv[1:])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement