Ejemplo n.º 1
0
    def update_info(self, steem_per_mvest=None, account_detail=None):
        c = Client(nodes=["https://api.hivekings.com"])

        if not steem_per_mvest:
            # get chain properties
            dygp = c.get_dynamic_global_properties()
            steem_per_mvest = (
                float(Amount(dygp["total_vesting_fund_steem"]).amount) /
                (float(Amount(dygp["total_vesting_shares"]).amount) / 1e6))

        # get account detail
        if not account_detail:
            account_detail = c.get_accounts([self.username])[0]
        vests = float(Amount(account_detail["vesting_shares"]))

        # calculate account age
        t = parse(account_detail["created"])
        if t.tzinfo is None:
            utc_time = pytz.timezone('UTC')
            t = utc_time.localize(t)

        # account reputation
        acc = Account(c)
        acc.raw_data = account_detail

        self.reputation = acc.reputation(precision=4)
        self.sp = vests / 1e6 * steem_per_mvest
        self.vests = vests
        self.account_age = (timezone.now() - t).total_seconds() / 86400
        self.post_count = account_detail["post_count"]
        self.save()

        return self
Ejemplo n.º 2
0
 def handle(self, *args, **options):
     users = User.objects.all()
     c = LightsteemClient(nodes=["https://hived.emre.sh"])
     dygp = c.get_dynamic_global_properties()
     steem_per_mvest = (
             float(Amount(dygp["total_vesting_fund_hive"]).amount) /
             (float(Amount(dygp["total_vesting_shares"]).amount) / 1e6))
     c = LightsteemClient(nodes=["https://hived.emre.sh"])
     for chunk in chunks(users, 500):
         account_details = c.get_accounts([c.username for c in chunk])
         for account_detail in account_details:
             try:
                 related_user = User.objects.get(
                     username=account_detail["name"])
             except User.DoesNotExist:
                 print(f"{account_detail['name']} is not found. Skipping.")
                 continue
             print("updating", related_user)
             related_user.update_info(
                 steem_per_mvest=steem_per_mvest,
                 account_detail=account_detail,
             )