コード例 #1
0
ファイル: imageuploader.py プロジェクト: dpays/dpaygo
    def upload(self, image, account, image_name=None):
        """ Uploads an image

            :param str/bytes image: path to the image or image in bytes representation which should be uploaded
            :param str account: Account which is used to upload. A posting key must be provided.
            :param str image_name: optional

            .. code-block:: python

                from dpaygo import DPay
                from dpaygo.imageuploader import ImageUploader
                stm = DPay(keys=["5xxx"]) # private posting key
                iu = ImageUploader(dpay_instance=stm)
                iu.upload("path/to/image.png", "account_name") # "private posting key belongs to account_name

        """
        account = Account(account, dpay_instance=self.dpay)
        if "posting" not in account:
            account.refresh()
        if "posting" not in account:
            raise AssertionError("Could not access posting permission")
        for authority in account["posting"]["key_auths"]:
            posting_wif = self.dpay.wallet.getPrivateKeyForPublicKey(authority[0])

        if isinstance(image, string_types):
            image_data = open(image, 'rb').read()
        elif isinstance(image, io.BytesIO):
            image_data = image.read()
        else:
            image_data = image

        message = py23_bytes(self.challenge, "ascii") + image_data
        signature = sign_message(message, posting_wif)
        signature_in_hex = hexlify(signature).decode("ascii")

        files = {image_name or 'image': image_data}
        url = "%s/%s/%s" % (
            self.base_url,
            account["name"],
            signature_in_hex
        )
        r = requests.post(url, files=files)
        return r.json()
コード例 #2
0
from win10toast import ToastNotifier
from dpaygo.account import Account
import time

if __name__ == "__main__":
    toaster = ToastNotifier()

    randowhale = Account("randowhale")
    randowhale.refresh()

    try:
        while True:
            time.sleep(15)
            randowhale.refresh()
            if randowhale.profile["name"] == "Rando Is Sleeping":
                # print(randowhale)
                print("still sleeping, awake in " +
                      randowhale.get_recharge_time_str(99))
            else:
                toaster.show_toast(randowhale.profile["name"],
                                   randowhale.profile["about"],
                                   icon_path=None,
                                   duration=5,
                                   threaded=True)
                # Wait for threaded notification to finish
                while toaster.notification_active():
                    time.sleep(0.1)

    except KeyboardInterrupt:
        pass