Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import sys
  4. import requests
  5. import argparse
  6. import urllib.request
  7. from urllib.parse import urlparse
  8. import os.path
  9. import json
  10. from pathlib import Path
  11.  
  12. parser = argparse.ArgumentParser(description='Instaprinter callback')
  13. parser.add_argument('--path', help='file full path')
  14. parser.add_argument('--key', help='Api key')
  15. parser.add_argument('--printer', help='Printer key')
  16.  
  17. args = parser.parse_args()
  18.  
  19. apiKey = args.key
  20. printer = args.printer
  21. fullpath = args.path
  22.  
  23. filename = os.path.basename(fullpath)
  24.  
  25. domain = "https://instaprinter.techlab.paris"
  26. apiVersion = "v01"
  27.  
  28. url = domain + "/api/" + apiVersion + "/" + printer + "/media/print"
  29. querystring = {"filename":filename}
  30. headers = {
  31. 'apikey': apiKey,
  32. 'cache-control': "no-cache",
  33. }
  34. response = requests.request("POST", url, headers=headers, params=querystring)
  35. response =json.loads(data.decode(encoding))
  36.  
  37. if 'success' in response:
  38. print("success file print and remove")
  39. else:
  40. print("callback error : " + response['error'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement