def upload(self, screenshot, name): ba = QByteArray() buf = QBuffer(ba) buf.open(QIODevice.WriteOnly) screenshot.save( buf, ScreenCloud.getScreenshotFormat()) #writes image into ba buf.close() json_data = json.dumps({'image': ba.toBase64().data()}) request = urllib2.Request(self.zapier_url, json_data, {"Content-Type": "application/json"}) try: reply = urllib2.urlopen(request) except Exception as e: ScreenCloud.setError("Could not upload to: " + self.zapier_url + "\n" + e.message) return False try: replyText = reply.read() ScreenCloud.setUrl(json.loads(replyText).link) except Exception as e: ScreenCloud.setError("Could not upload to: " + self.zapier_url + "\n" + e.message) return False return True
def upload(self, screenshot, name): q_byte_array = QByteArray() q_buffer = QBuffer(q_byte_array) q_buffer.open(QIODevice.WriteOnly) screenshot.save(q_buffer, ScreenCloud.getScreenshotFormat()) # writes image to byte array q_buffer.close() json_data = json.dumps({'image': str(q_byte_array.toBase64())}) #f = open('/tmp/zapier', 'w') #f.write("{}\n{}\n\n".format(self.zapier_url, json_data)) #f.close() response = requests.post(url=self.zapier_url, data=json_data, headers={'Content-Type': 'application/json'}) try: response.raise_for_status() except Exception as e: ScreenCloud.setError("Could not upload to: " + self.zapier_url + "\n" + e.message) return False try: ScreenCloud.setUrl(response.json()['link']) except Exception as e: ScreenCloud.setError("Upload to {} worked, but response was invalid: {}\n{}".format(self.zapier_url, response.content, e.message)) return False return True
def upload(self, screenshot, name): self.loadSettings() #Save to memory buffer ba = QByteArray() buf = QBuffer(ba) buf.open(QIODevice.ReadWrite) screenshot.save(buf, ScreenCloud.getScreenshotFormat()) #Create folder if not exists folders = self.driveService.files().list( q="name='%s' and mimeType='application/vnd.google-apps.folder' and trashed=false" % (self.folderName)).execute()["files"] exists = len(folders) > 0 if not exists: folderMetadata = { 'name': self.folderName, 'mimeType': 'application/vnd.google-apps.folder' } folder = self.driveService.files().create(body=folderMetadata, fields='id').execute() else: folder = folders[0] #Upload fileMetadata = {'name': name, 'parents': [folder["id"]]} media = MediaInMemoryUpload(ba.data(), mimetype='image/' + ScreenCloud.getScreenshotFormat()) file = self.driveService.files().create( body=fileMetadata, media_body=media, fields='webViewLink, id').execute() if self.copyLink: webViewLink = file.get('webViewLink') ScreenCloud.setUrl(webViewLink) return True
def upload(self, screenshot, name): self.loadSettings() q_ba = QByteArray() q_buff = QBuffer(q_ba) q_buff.open(QIODevice.WriteOnly) screenshot.save(q_buff, ScreenCloud.getScreenshotFormat()) q_buff.close() url = (self.host + '/upload').replace('//upload', '/upload') form = MultiPartForm() form.add_field('token', self.token) form.add_file('file', self.getFilename(), q_ba.data()) data = bytes(form) r = urllib.request.Request(url, data, headers={ 'Content-Type': form.get_content_type(), 'Content-Length': len(data), 'User-Agent': 'XBackBone/Screencloud-client' }) try: res = urllib.request.urlopen(r) response = json.loads(res.read().decode('utf-8')) url = response.get('url') if not url: raise Exception(response.get('message')) ScreenCloud.setUrl(url) except urllib.error.HTTPError as e: response = json.loads(e.read()) ScreenCloud.setError('Error while connecting to: ' + self.host + '\n' + response.get('message')) return False except Exception as e: try: ScreenCloud.setError('Could not upload to: ' + self.host + '\nError: ' + str(e)) except AttributeError: ScreenCloud.setError('Unexpected error while uploading:\n' + traceback.format_exc()) return False return True
def send(self, bytestr): for cli in self.clients: if self.clients[cli] == "callback": cli.write( QByteArray((len(bytestr) + ipcdata.longlen ).to_bytes(ipcdata.longlen, byteorder='big') + bytestr))
def handleFunction(self, cli, buf): data = ipcdata(init=buf) name = data.read() if hasattr(ts3lib, name): args = [] while not data.atEnd(): args.append(data.read()) ret = getattr(ts3lib, name)(*args) if ret: data = ipcdata(obj=ret) else: data = ipcdata(obj=tuple()) cli.write( QByteArray((len(data.data) + ipcdata.longlen ).to_bytes(ipcdata.longlen, byteorder='big') + data.data)) else: err = ts3lib.logMessage("Unknown method data %s" % data.data, ts3defines.LogLevel.LogLevel_ERROR, "pyTSon.ipcplugin", 0) if err != ts3defines.ERROR_ok: print("Unknown method data in ipcplugin: %s" % data.data)
def loadBadges(self, reply): try: data = reply.readAll().data() # .decode('utf-8') self.badges = parseBadgesBlob(QByteArray(data))[0] except: ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0) (tstamp, self.badges, array) = loadBadges() del self.nwmc_badges
def parseBadgesBlob(blob: QByteArray): ret = {} next = 12 guid_len = 0 guid = "" name_len = 0 name = "" url_len = 0 url = "" filename = "" desc_len = 0 desc = "" for i in range(0, blob.size()): try: if i == next: #guid_len guid_len = int(blob.at(i)) guid = str(blob.mid(i + 1, guid_len)) elif i == (next + 1 + guid_len + 1): name_len = int(blob.at(i)) name = str(blob.mid(i + 1, name_len)) elif i == (next + 1 + guid_len + 1 + name_len + 2): url_len = int(blob.at(i)) url = str(blob.mid(i + 1, url_len)) filename = url.rsplit('/', 1)[1] elif i == (next + 1 + guid_len + 1 + name_len + 2 + url_len + 2): desc_len = int(blob.at(i)) desc = str(blob.mid(i + 1, desc_len)) ret[guid] = { "name": name, "url": url, "filename": filename, "description": desc } next = (next + guid_len + 2 + name_len + 2 + url_len + 2 + desc_len + 13) delimiter = blob.mid(0, 12) except: from traceback import format_exc ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0) pass return ret, blob
def upload(self, screenshot, name): ba = QByteArray() buf = QBuffer(ba) buf.open(QIODevice.WriteOnly) screenshot.save( buf, ScreenCloud.getScreenshotFormat() ) #writes image into ba buf.close() json_data = json.dumps({'image': ba.toBase64().data()}) request = urllib2.Request(self.zapier_url, json_data, {"Content-Type": "application/json"}) try: reply = urllib2.urlopen(request) except Exception as e: ScreenCloud.setError("Could not upload to: "+ self.zapier_url + "\n" + e.message) return False try: replyText = reply.read() ScreenCloud.setUrl(json.loads(replyText).link) except Exception as e: ScreenCloud.setError("Could not upload to: "+ self.zapier_url + "\n" + e.message) return False return True
def loadBadges(): """ Loads Badges from ts3settings.db :return: int(timestamp), str(ret), dict(badges) """ db = ts3client.Config() q = db.query("SELECT * FROM Badges") # WHERE key = BadgesListData timestamp = 0 ret = {} badges = QByteArray() while q.next(): key = q.value("key") if key == "BadgesListTimestamp": timestamp = q.value("value") elif key == "BadgesListData": ret, badges = parseBadgesBlob(q.value("value")) del db return timestamp, ret, badges
def getArrayData(self, i): name = self.getArrayName(i) if name not in self._buffers: data = self.arrays.items()[i][1].data shape = data.shape buf = numpy.getbuffer(data if len(shape) == 1 else data.reshape(( shape[0] * shape[1]))) ba = QByteArray() ba.reserve(len(buf)) ba.append(str(buf), len(buf)) self._buffers[name] = ba return self._buffers[name]
def onClientData(self, cli): if self.clients[cli] == "unknown": clitype = cli.read(1) if clitype == b'f': self.clients[cli] = "function" self.buf[cli] = bytes() if cli.bytesAvailable() == 0: return elif clitype == b'c': self.clients[cli] = "callback" return else: cli.write(QByteArray("Unknown client type")) cli.disconnectFromServer() cli.delete() return elif self.clients[cli] == "callback": return self.buf[cli] += cli.read(cli.bytesAvailable()).data() self.handleBuffer(cli)