Пример #1
0
    def upload(self, image, account, image_name=None):
        """ Uploads an image

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

            .. code-block:: python

                from bhive import Hive
                from bhive.imageuploader import ImageUploader
                hv = Hive(keys=["5xxx"]) # private posting key
                iu = ImageUploader(hive_instance=hv)
                iu.upload("path/to/image.png", "account_name") # "private posting key belongs to account_name

        """
        account = Account(account, hive_instance=self.hive)
        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.hive.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 bhive.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