added more doocstrings and improved the readme
This commit is contained in:
15
README.md
15
README.md
@@ -21,6 +21,21 @@ if __name__ == '__main__':
|
|||||||
2. Navigate to this directory, and run ```make_cfg_tool_exe.py build``` on Windows or ```python3 make_cfg_tool_exe.py``` on Mac or UNIX.
|
2. Navigate to this directory, and run ```make_cfg_tool_exe.py build``` on Windows or ```python3 make_cfg_tool_exe.py``` on Mac or UNIX.
|
||||||
|
|
||||||
### Interfacing with miners programmatically
|
### Interfacing with miners programmatically
|
||||||
|
<br>
|
||||||
|
|
||||||
|
##### Note: If you are trying to interface with Whatsminers, there is a bug in the way they are interacted with on Windows, so to fix that you need to change the event loop policy using this code:
|
||||||
|
```python
|
||||||
|
# need to import these 2 libraries, you need asyncio anyway so make sure you have sys imported
|
||||||
|
import sys
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
# if the computer is windows, set the event loop policy to a WindowsSelector policy
|
||||||
|
if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
|
||||||
|
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||||
|
```
|
||||||
|
|
||||||
|
##### It is likely a good idea to use this code in your program anyway to be preventative.
|
||||||
|
<br>
|
||||||
|
|
||||||
To write your own custom programs with this repo, you have many options.
|
To write your own custom programs with this repo, you have many options.
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
"""
|
||||||
|
This file stores the MinerFactory instance used by the ConfigUtility for use in other files.
|
||||||
|
"""
|
||||||
|
|
||||||
from miners.miner_factory import MinerFactory
|
from miners.miner_factory import MinerFactory
|
||||||
|
|
||||||
miner_factory = MinerFactory()
|
miner_factory = MinerFactory()
|
||||||
|
|||||||
@@ -16,6 +16,14 @@ class MinerFactory:
|
|||||||
self.miners = {}
|
self.miners = {}
|
||||||
|
|
||||||
async def get_miner_generator(self, ips: list):
|
async def get_miner_generator(self, ips: list):
|
||||||
|
"""
|
||||||
|
Get Miner objects from ip addresses using an async generator.
|
||||||
|
|
||||||
|
Returns an asynchronous generator containing Miners.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
ips: a list of ip addresses to get miners for.
|
||||||
|
"""
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
scan_tasks = []
|
scan_tasks = []
|
||||||
for miner in ips:
|
for miner in ips:
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class MinerNetwork:
|
|||||||
return ipaddress.ip_network(f"{default_gateway}/{subnet_mask}", strict=False)
|
return ipaddress.ip_network(f"{default_gateway}/{subnet_mask}", strict=False)
|
||||||
|
|
||||||
async def scan_network_for_miners(self) -> None or list:
|
async def scan_network_for_miners(self) -> None or list:
|
||||||
"""Scan the network for miners, and """
|
"""Scan the network for miners, and return found miners as a list."""
|
||||||
local_network = self.get_network()
|
local_network = self.get_network()
|
||||||
print(f"Scanning {local_network} for miners...")
|
print(f"Scanning {local_network} for miners...")
|
||||||
scan_tasks = []
|
scan_tasks = []
|
||||||
@@ -55,6 +55,11 @@ class MinerNetwork:
|
|||||||
return miners
|
return miners
|
||||||
|
|
||||||
async def scan_network_generator(self):
|
async def scan_network_generator(self):
|
||||||
|
"""
|
||||||
|
Scan the network for miners using an async generator.
|
||||||
|
|
||||||
|
Returns an asynchronous generator containing found miners.
|
||||||
|
"""
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
local_network = self.get_network()
|
local_network = self.get_network()
|
||||||
scan_tasks = []
|
scan_tasks = []
|
||||||
|
|||||||
Reference in New Issue
Block a user