-
-
Save icsaas/033a2df260d19c9f0fd93e1b3ca31673 to your computer and use it in GitHub Desktop.
TrueRandom.ipynb
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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/Seele0oO/4eba6f1f6c30914964d65425979016e7/bitcoinhashrandom.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "GsyCzIBra6ks" | |
}, | |
"source": [ | |
"!pip install requests\n", | |
"# 使用方法\n", | |
"### 自行选定开奖时间并在到达时间时运行此程序\n", | |
"### 填写参与抽奖的用户名\n", | |
"### 然后点击runAll,到最下面查看结果" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"id": "P5Thkc3lXQ73" | |
}, | |
"outputs": [], | |
"source": [ | |
"userlist=[\"a\",\"b\",\"c\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"id": "c2AC3g0nZAgD" | |
}, | |
"outputs": [], | |
"source": [ | |
"import os,time\n", | |
"\n", | |
"os.environ['TZ'] = 'Asia/Shanghai'\n", | |
"time.tzset() " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "ar1710VDPt8O" | |
}, | |
"source": [ | |
"获取最新的block" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"id": "7BJNkq0MPrLn" | |
}, | |
"outputs": [], | |
"source": [ | |
"def getHashs():\n", | |
" import time,requests\n", | |
" url = \"https://blockexplorer.one/ajax/btc/mainnet/blocks\"\n", | |
" result = requests.get(url)\n", | |
" data=result.json()\n", | |
" print(data[0])\n", | |
" get_hash=data[0]['hash']\n", | |
" get_time=data[0]['timestamp']\n", | |
" ctime=int(int(time.time()))\n", | |
" # print(get_hash)\n", | |
" # print(get_time)\n", | |
" hash=\"0X{}\".format(get_hash)\n", | |
" # hex to dex\n", | |
" hash=int(hash,16)\n", | |
" get_hash=hash\n", | |
" # print(get_hash)\n", | |
" return get_hash,get_time" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "R27c-CJSSmI9", | |
"outputId": "f764920f-d24d-4533-fb1c-719bc4cc2906" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"{'hash': '000000000000000000022272753f2056d5de2309dcfc0c7add4eb4e71d9dd70d', 'size': '1,500,350', 'height': 721866, 'datetime': '2022-02-05 05:08:28 UTC', 'time': 1644037708, 'mediantime': '2022-02-05 04:21:21 UTC', 'nonce': 611214714, 'bits': '170a8bb4', 'difficulty': 26690525287405.5, 'previousblockhash': '0000000000000000000a5bb1a6e7f8083393412c663c74d5e1a6964a6de90878', 'transactions': 2368, 'confirmations': 1, 'timestamp': 1644037708, 'omniTransactions': 4, 'reward': 6.25, 'rewardUsd': '259,642.47', 'humanDiff': '3 minutes ago', 'dateString': '05/02/2022 - 05:08:28 UTC'}\n", | |
"204450133405904284836502263606628101135365038262834957\n", | |
"1644037708\n" | |
] | |
} | |
], | |
"source": [ | |
"get_hash,get_time=getHashs()\n", | |
"print(get_hash)\n", | |
"print(get_time)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "tQg88J9xXKtu", | |
"outputId": "71f5be35-b893-438a-ad7d-90f4e6cd9553" | |
}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"当前hash(dex): 204450133405904284836502263606628101135365038262834957\n", | |
"hashTime: 2022-02-05 13:08:28\n", | |
"Time: 2022-02-05 13:11:53\n", | |
"The luckly user is: c\n" | |
] | |
} | |
], | |
"source": [ | |
"import time\n", | |
"hash=get_hash\n", | |
"print(\"当前hash(dex):\",hash)\n", | |
"userSum = len(userlist)\n", | |
"n=hash%userSum\n", | |
"print(\"hashTime:\",time.strftime(\"%Y-%m-%d %H:%M:%S\",time.localtime(get_time)))\n", | |
"print(\"Time: {}\".format( time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime()) )+\"\\n\"+\"The luckly user is: \"+userlist[n])" | |
] | |
} | |
], | |
"metadata": { | |
"colab": { | |
"name": "TrueRandom.ipynb", | |
"provenance": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"display_name": "Python 3", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.10.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment