33import hashlib
44import struct
55import time
6+ import os
67
8+ def get_input (prompt , data_type = str ):
9+ while True :
10+ try :
11+ value = data_type (input (prompt ))
12+ return value
13+ except ValueError :
14+ print (f"Invalid input. Please enter a valid { data_type .__name__ } ." )
15+
16+ if os .path .isfile ('config.json' ):
17+ print ("config.json found,start mining" )
18+ with open ('config.json' ,'r' ) as file :
19+ config = json .load (file )
20+ pool_address = config ['pool_address' ]
21+ pool_port = config ["pool_port" ]
22+ username = config ["user_name" ]
23+ password = config ["password" ]
24+ min_diff = config ["min_diff" ]
25+ else :
26+ print ("config.json doesn't exist,generating now" )
27+ pool_address = get_input ("Enter the pool address: " )
28+ pool_port = get_input ("Enter the pool port: " , int )
29+ user_name = get_input ("Enter the user name: " )
30+ password = get_input ("Enter the password: " )
31+ min_diff = get_input ("Enter the minimum difficulty: " , float )
32+ config_data = {
33+ "pool_address" : pool_address ,
34+ "pool_port" : pool_port ,
35+ "user_name" : user_name ,
36+ "password" : password ,
37+ "min_diff" : min_diff
38+ }
39+ with open ("config.json" , "w" ) as config_file :
40+ json .dump (config_data , config_file , indent = 4 )
41+ print ("Configuration data has been written to config.json" )
42+
743with open ('config.json' , 'r' ) as file :
844 config = json .load (file )
945
@@ -147,4 +183,4 @@ def submit_solution(sock, job_id, extranonce2, ntime, nonce):
147183 submit_solution (sock , * result )
148184 except Exception as e :
149185 print (f"An error occurred: { e } . Reconnecting..." )
150- time .sleep (5 )
186+ time .sleep (5 )
0 commit comments