Created
February 1, 2018 09:19
-
-
Save xeroc/f1bd2c9e21cec249c53361c4e0251ee0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import pika | |
import sys | |
import json | |
import config | |
from piston.account import Account | |
from .models import User | |
from .maillog import logmodule | |
from .operationsqueue import OperationsQueue | |
log = logmodule(__name__) | |
class Worker(OperationsQueue): | |
def process(self, op): | |
# For account authorization | |
if (op["type"] == "account_update"): | |
account_name = op["account"] | |
user = User.query.filter_by( | |
steem_account=account_name | |
).first() | |
# Test if authentication is changed | |
if user and op.get("posting", None): | |
log.info("Processing Account Authorization") | |
found = False | |
for auths in op["posting"]["account_auths"]: | |
if auths[0] == config.steem_account: | |
user.authorizeSteem() | |
found = True | |
break | |
if user.isauthorized() and not found: | |
user.unAuthorizeSteem() | |
# Test if profile image is changed | |
if user and op.get("json_metadata", None): | |
log.info("Processing json_metadata update on block %d" % op["block_num"]) | |
try: | |
steem_account = Account( | |
account_name, | |
steem_instance=self.steem | |
) | |
metadata = json.loads(steem_account["json_metadata"]) | |
if isinstance(metadata, str): | |
metadata = json.loads(metadata) | |
profile_image = ( | |
metadata | |
.get("profile", {}) | |
.get("profile_image", None)) | |
if profile_image and isinstance(profile_image, str) and profile_image[:4].lower() == "http": | |
user.update_profile_image(profile_image) | |
except Exception as e: | |
# log.error(str(e)) | |
pass | |
self.updateStatus(op["block_num"]) | |
def run(begin=None, end=None): | |
worker = Worker( | |
"account.update", | |
["account_update"] | |
) | |
worker.start(begin, end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment