termpad.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. # termpad.py
  3. # This uses the termpad pastebin website to do a variety of things.
  4. #
  5. # Dependencies: curl, xclip (optional).
  6. import os
  7. import subprocess
  8. import argparse
  9. import platform
  10. browser = "palemoon"
  11. parser = argparse.ArgumentParser(description='Termpad curl python script')
  12. parser.add_argument('-g', '--get', type=str, metavar='ID', help='Get a pasted document')
  13. parser.add_argument('-o', '--open', type=str, metavar='ID', help='Open a termpad link in a browser.')
  14. parser.add_argument('-p', '--paste', type=str, metavar='PATH', help='Paste an existing file.')
  15. parser.add_argument('-c', '--copy', action="store_true", default=False, help='Copy the link to the pasted file')
  16. args = parser.parse_args()
  17. if args.get:
  18. if args.get == "":
  19. print("Please give a termpad URL/Paste ID")
  20. elif args.get.startswith("https://termpad.com"):
  21. if "https://termpad.com/" in args.get:
  22. paste_id = args.get.split("/")[-1]
  23. else:
  24. paste_id = args.get
  25. text = subprocess.getoutput(f"curl --silent https://termpad.com/raw/{paste_id}")
  26. print(text)
  27. elif args.paste:
  28. if os.path.isfile(args.paste):
  29. paste_url = subprocess.getoutput(f'curl --silent --data-binary @"{args.paste}" termpad.com')
  30. print(paste_url)
  31. if args.copy == True:
  32. if platform.system() == "Windows":
  33. os.system(f"echo {paste_url} | clip")
  34. else:
  35. os.system(f"echo '{paste_url}' | xclip -selection clipboard")
  36. else:
  37. print("This is not a file")
  38. elif args.open:
  39. if args.open.startswith("https://termpad.com"):
  40. if platform.system() == "Windows":
  41. os.system(f"start {args.open}")
  42. else:
  43. os.system(f"xdg-open {args.open}")
  44. else:
  45. print("This is not a termpad URL")
  46. else:
  47. parser.print_help()