Created
May 23, 2018 03:19
-
-
Save myrual/6a56a344bd244f95a89b57b18e4ca4b8 to your computer and use it in GitHub Desktop.
an example for read user asset list
This file contains 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
# -*- coding: utf-8 -*- | |
import web | |
import json | |
import requests | |
import jwt | |
import datetime | |
import calendar | |
import hashlib | |
import base64 | |
import Crypto | |
import time | |
import uuid | |
import random | |
from Crypto.PublicKey import RSA | |
from Crypto.Cipher import AES | |
from Crypto import Random | |
from Crypto.Cipher import PKCS1_OAEP | |
private_key = """-----BEGIN RSA PRIVATE KEY----- | |
-----END RSA PRIVATE KEY-----""" | |
mixin_pin_token = """csEaHIh5RuVcXqcJ9aNp/AoubC/0L9ZtGWn037XREiR5JlbAvDW52obceJ9wWxVB12V9QxmabGmGR59wLoyfhfQeSVer56jOIUrOgL4ZXaMq32Rsddp2wpydEsCJbIjDftKwHJJvfz0XFAsNeBCTC+OfouaLW86Q50g3p7razbM=""" | |
urls = ( | |
'/', 'userEntrance', | |
'/auth','auth', | |
'/credit','userEntrance' | |
) | |
mixin_client_id = "" | |
mixin_client_secret = "" | |
mixin_pay_pin = '' | |
mixin_pay_sessionid = '' | |
class userEntrance: | |
def GET(self): | |
raise web.seeother('https://mixin.one/oauth/authorize?client_id=a932cac1-e05b-4095-b662-f5ab284050bf&scope=PROFILE:READ+ASSETS:READ') | |
class auth: | |
def GET(self): | |
mixindata = web.input(code = "no") | |
print(mixindata) | |
if mixindata.code == "no": | |
return "I don't know you, can not give your bonus" | |
r = requests.post('https://api.mixin.one/oauth/token', json = {"client_id": mixin_client_id, "code": mixindata.code,"client_secret": mixin_client_secret}) | |
result = r.json() | |
print(result) | |
if "data" not in result or "access_token" not in result["data"]: | |
return "I don't know you, can not give your bonus" | |
access_token = result["data"]["access_token"] | |
personinfo = requests.get('https://api.mixin.one/me', headers = {"Authorization":"Bearer " + access_token}) | |
userid = personinfo.json()["data"]["user_id"] | |
print(personinfo.json()) | |
assets_of_user = requests.get('https://api.mixin.one/assets', headers = {"Authorization":"Bearer " + access_token}) | |
assets_info = assets_of_user.json()["data"] | |
htmlbody = "" | |
totalAssetInUSD = 0.0 | |
for singleAsset in assets_info: | |
if singleAsset["price_usd"] != "0": | |
print(singleAsset["name"] + " id " + singleAsset["asset_id"]) | |
else: | |
print(singleAsset["name"].encode('utf-8') + " id ".encode('utf-8') + singleAsset["asset_id"].encode('utf-8')) | |
if singleAsset["price_usd"] != "0" and singleAsset["balance"] != "0": | |
totalAssetInUSD = totalAssetInUSD + float(singleAsset["balance"]) * float(singleAsset["price_usd"]) | |
print("totalAssetInUSD is :" + str(totalAssetInUSD)) | |
assetstring = "<img src=" + singleAsset["icon_url"] + ">" + singleAsset["name"] + " : " + singleAsset["balance"] | |
htmlbody = htmlbody + assetstring + "<br>" | |
print(assetstring) | |
sendmessage_body = {} | |
credit = int(totalAssetInUSD/2.0) | |
totalUSDString = "Your credit: $ " + str(credit) | |
return """<!DOCTYPE html> | |
<html> | |
<head> | |
<title>""" + totalUSDString + """</title> | |
</head> | |
<body> | |
<h1> Contact me at mixin with mixin id 31367 to know more</h1> | |
<h1>Service provided by <a href="https://babelbank.io">Babel</a></h1> | |
</body> | |
</html> """ | |
if __name__ == "__main__": | |
app = web.application(urls, globals()) | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment