Skip to content

Instantly share code, notes, and snippets.

@Seele0oO
Last active January 29, 2023 02:53
Show Gist options
  • Save Seele0oO/4eba6f1f6c30914964d65425979016e7 to your computer and use it in GitHub Desktop.
Save Seele0oO/4eba6f1f6c30914964d65425979016e7 to your computer and use it in GitHub Desktop.
TrueRandom.ipynb
Display the source blob
Display the rendered blob
Raw
{
"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]['time']\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": "e4caa8cf-a39b-49b9-9b5d-430905dc680a"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"{'hash': '000000000000000000004e046bfabb076176d5b8875b1ceb2ccd2c3fd3dd0856', 'size': '1,532,723', 'height': 721781, 'datetime': '2022-02-04 10:44:51 UTC', 'time': 1643971491, 'mediantime': '2022-02-04 10:13:28 UTC', 'nonce': 2083013213, 'bits': '170a8bb4', 'difficulty': 26690525287405.5, 'previousblockhash': '000000000000000000028eb9b6ce715d3d690bd60a7d45037ae2fd2e116d6c06', 'transactions': 1860, 'confirmations': 1, 'timestamp': 1643971491, 'omniTransactions': 3, 'reward': 6.25, 'rewardUsd': '237,313.28', 'humanDiff': '23 minutes ago', 'dateString': '04/02/2022 - 10:44:51 UTC'}\n",
"29189727154264079863797878063551912059282419005327446\n",
"1643971491\n"
]
}
],
"source": [
"!pip install requests\n",
"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": "8a338887-9150-4683-95f3-12942b9e4381"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"当前hash: 29189727154264079863797878063551912059282419005327446\n",
"hashTime: 2022-02-04 18:44:51\n",
"Time: 2022-02-04 19:08:49\n",
"The luckly user is: a\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": [],
"toc_visible": true,
"history_visible": true,
"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