myhashrate=1000
import locale
from datetime import datetime
import requests
login_url = "https://api.qubic.li/Auth/Login"
login_payload = {
    "userName": "guest@qubic.li",
    "password": "guest13@Qubic.li"
}
login_headers = {
    "Content-Type": "application/json",
    "Origin": "https://app.qubic.li",
    "Referer": "https://app.qubic.li/"
}
login_response = requests.post(login_url, json=login_payload, headers=login_headers)
token = login_response.json().get("token")   

url = "https://api.qubic.li/Score/Get"
headers = {
    'Accept': 'application/json',
    "Authorization": f"Bearer {token}"
}
response = requests.get(url, headers=headers)    
scores_dict = response.json()
price_url="https://tradeogre.com/api/v1/ticker/QUBIC-USDT"
price_response=requests.get(price_url)
price_dict=price_response.json()
qubic_price=float(price_dict["price"])
epoch = scores_dict['scoreStatistics'][0]['epoch']
net_it=scores_dict['estimatedIts']

total_scores=0
for scores in scores_dict['scores']:
    score=int(scores['score'])
    total_scores+=score

sol_h=scores_dict['solutionsPerHour']
avg=round(scores_dict['averageScore'],2)
sol_d=round(sol_h/(net_it/myhashrate)*24,2)
it_price=0.85*qubic_price*(1000000000000/net_it/7/1.06)
sol_coin=int(0.85*(1000000000000/1.06)/(sol_h*24*7))
sol_coin_fixed=int(0.7*(1000000000000/1.06)/(sol_h*24*7))

my_rev=myhashrate*it_price
locale.setlocale(locale.LC_TIME, 'zh_CN')
now = datetime.now()
formatted_time = now.strftime("%Y-%m-%d %H:%M <%A>")
sol_url = "https://api.qubic.li/My/Pool/f4535705-eeac-4c4f-9ddc-4c3a91b40b13/Performance"
sol_response=requests.get(sol_url,headers=headers)
sol_dict=sol_response.json()
my_sol=sol_dict["foundSolutions"]
ratio=my_sol/(avg*1.06)
sum_it=0
for miner in sol_dict["miners"]:
    sum_it+=miner["currentIts"]
if sum_it != 0:
    avg_sum_sol=(sol_h/(net_it/sum_it))*(total_scores/sol_h)
else:
    avg_sum_sol=0
coin_rev_85=int(1257396449*(ratio))
coin_rev_70=int(1035502958*(ratio))
print('-'*50)
print('奖励形式：Fixed Reward 85% | Fixed+Bonus Reward 1/2')
print('-'*50)
print("当前时间：", formatted_time)
print('当前纪元：',epoch)
print('全网算力:',net_it, ' it/s','\n每小时Solution数量：',sol_h,'\n当前平均分：',avg)
print('当前Qubic价格：',"{:.8f}$".format(qubic_price))
print('当前1个Solution预估币量 ：',"{:,}".format(sol_coin),'|',"{:,}".format(sol_coin_fixed))
print('-'*50)
print(myhashrate,'算力每日Solution产出：',sol_d)
print(myhashrate,"算力每日收益(USDT)：","{:.2f}".format(my_rev))
print(myhashrate,"算力每日收益(RMB)：","{:.2f}".format(my_rev*7.2))
print('-'*50)
print('在线矿机数量：',len(sol_dict["miners"]))
print('在线矿机总算力：',sum_it,'it/s')
print(sum_it,'算力全网截至目前平均Solution产出：',"{:.2f}".format(avg_sum_sol))
print('我找到的Solution：',my_sol)
if avg_sum_sol != 0:
    luck_val=my_sol/avg_sum_sol
else:
    luck_val=0
if luck_val >= 1:
    print("我的幸运值(1为平均值）：",f"\033[32m{luck_val:.2f}   \U0001F604\033[0m")
else:
    print("我的幸运值(1为平均值）：",f"\033[31m{luck_val:.2f}  \U0001F641\033[0m")
print('当前预计分配比例：',"{:.2f}%".format(ratio*100))
print('预计收益（币）：','{:,}'.format(coin_rev_85),'|','{:,}'.format(coin_rev_70))
print('预计收益（USDT):','{:.2f}'.format(coin_rev_85*qubic_price),'|','{:.2f}'.format(coin_rev_70*qubic_price))
print('预计收益（RMB):','{:.2f}'.format(coin_rev_85*qubic_price*7.2),'|','{:.2f}'.format(coin_rev_70*qubic_price*7.2))
print('-'*50)