Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from connection import Connection
  2. import json
  3. import requests
  4. import mimetypes
  5. import uuid
  6. import os
  7.  
  8. def callback_converter(ch, method, properties, body):
  9.     json_get = json.loads(body)
  10.     file_path = json_get['file_path']
  11.     print file_path
  12.     response = requests.get(file_path)
  13.     content_type = response.headers['content-type']
  14.     extension = mimetypes.guess_extension(content_type)
  15.     hash = uuid.uuid4().hex
  16.     fullPath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + '/converter-node/files/' + hash + extension
  17.     with open(fullPath, 'wb') as f:
  18.         f.write(response.content)
  19.  
  20. connector = Connection(host='35.198.191.27', login='prosperodesu', password='s45fdfx65')
  21. connector.addCallback('convert', callback_converter)
  22. connector.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement