Ease developers to use queue/threads functions to handle big amount of data
Project description
pyhacks
Python module to ease writing scripts go over big amount of data in order to perform the same actions. A simple preconfigured threads and queue management and more hacking utils
Will elaborate more when it will get mature enough :)
capabilities
PyHacks
Using all below capabilities to easily manage threads and queue to perform operations on Item objects.
from pyhacks import PyHacks, Net
if __name__ == "__main__":
net = Net()
def handle_item(item):
host = item.get("host")
url = item.get("url")
replied_to_ping = net.reply_to_ping(host)
ip = net.resolve(host)
if ip == None:
return False
item.set("Reply To Ping", replied_to_ping)
item.set("ip", ip)
hacks.logger.green("{} {} {}".format(host, replied_to_ping, ip))
hacks.exporter.put(item)
return True
hacks = PyHacks(handle_item, 25, "output.csv")
hosts = hacks.parse.csv("ips.csv")
for host in hosts:
hacks.qt.put(host)
hacks.finish()
QueueThreads
QueueThreads class allows you to manage queue and threads easily.
qt = QueueThreads(handle_function, num_worker_threads, logger)
qt.put({"counter":1, "key1":"value1"})
qt.finish() # waiting until job is finished
parameters
handle_function - a function recevies item parameter from queue, will be used in all threads defined, return value has to be bool
def handle_item(item):
host = item.get("host")
url = item.get("url")
replied_to_ping = net.reply_to_ping(host)
ip = net.resolve(host)
if ip == None:
return False
item.set("Reply To Ping", replied_to_ping)
item.set("ip", ip)
hacks.logger.green("{} {} {}".format(host, replied_to_ping, ip))
hacks.exporter.put(item)
return True
num_worker_threads - numbers of threads used to run handle_functions on queue items logger - a Logger instance to be used for automatic logging
Parser
Parse files and returns list of Item objects
parse = Parser()
items = parse.csv("ips.csv")
for item in items:
qt.put(item)
Logger
Easy logging mechanism + writing into files under logs directory, used by QueueThreads for autoamtic logging
logger = Logger(verbose=False)
logger.green("text")
logger.red("text")
logger.yellow("text")
Exporter
Exporting Item objects into a csv/txt file
export = Exporter(output.csv)
export.put({"counter":1,"key1":"value"})
export.finish()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pyhacks-1.0.20.tar.gz.
File metadata
- Download URL: pyhacks-1.0.20.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9e645c62c2a2054b347d3bf14a48cd2b5001a608330b41702e13a69efab2a8a
|
|
| MD5 |
7f399f02d5193217c1a121ee316dcaf3
|
|
| BLAKE2b-256 |
9c24842df84f1b082d710cff146baa87fd1c3b174050e6b100180a36da05afe7
|