No project description provided
Project description
CrawlerCodePythonTools - Documentation
Tools for python by CrawlerCode.
Installation
pip install CrawlerCodePythonTools
Config
from pythontools.core import config
cfg = config.Config(path="", default_config={"config_data_1": "value_123"})
cfgData = cfg.getConfig()
# get config value
print(cfgData["config_data_1"])
# chang value and save config
cfgData["config_data_1"] = "value_456"
cfg.saveConfig()
Logger
from pythontools.core import logger
# path to logs directory (not necessary)
logger.initLogDirectory("logs")
# print color test
logger.log("§1Blue §9Light-Blue §3Cyan §bLight-Cyan §4Red §cLight-Red §6Yellow §eLight-Yellow §2Green §aLight-Green §5Magenta §dLight-Magenta §fWhite §7Light-Gray §8Gray §0Black")
TelegramBot
from pythontools.telegrambot import telegrambot
BOT = telegrambot.TelegramBot(token="TOKEN")
BOT.trustUserByID(id="USER-ID")
BOT.start()
# send message
BOT.sendMessage(chat_id="CHAT-ID", text="This is a message!")
# recipe messages
def recipeMessages(message):
print("message:", message.text)
message.reply("answer.")
BOT.registerMessageHandler(recipeMessages)
# handle commands
def handleCommand(command):
print("command: test")
BOT.registerCommand('test', handleCommand)
WebBot
- Download chromedriver or geckodriver
from pythontools.webbot import webbot
# Google Chrome
browser = webbot.WebBot().Chrome(chromedriver="chromedriver.exe")
# Firefox
browser = webbot.WebBot().Firefox(geckodriver="geckodriver.exe")
browser.get("https://www.google.com/")
browser.input('//*[@id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input', "what is python?")
browser.click('//*[@id="tsf"]/div[2]/div[1]/div[2]/div[2]/div[2]/center/input[1]')
time.sleep(10)
browser.close()
Server and Client (sockets)
Server
from pythontools.core import events
from pythontools.sockets import server
from threading import Thread
SERVER = server.Server(password="PASSWORD")
def ON_CLIENT_CONNECT(params):
client = params[0]
def ON_CLIENT_DISCONNECT(params):
client = params[0]
def ON_RECEIVE(params):
client = params[0]
data = params[1]
METHOD = data["METHOD"]
events.registerEvent("ON_CLIENT_CONNECT", ON_CLIENT_CONNECT)
events.registerEvent("ON_CLIENT_DISCONNECT", ON_CLIENT_DISCONNECT)
events.registerEvent("ON_RECEIVE", ON_RECEIVE)
Thread(target=SERVER.start, args=["HOST-IP", 15749]).start()
# send client a message
SERVER.sendToClient("MY_CLIENT_ID", {"METHOD": "TEST", "mydata": "123"})
Client
from pythontools.core import events
from pythontools.sockets import client
from threading import Thread
CLIENT = client.Client(password="PASSWORD", clientID="MY_CLIENT_ID", clientType="CLIENT")
def ON_CONNECT(params):
pass
def ON_RECEIVE(params):
data = params[0]
METHOD = data["METHOD"]
# recipe the test message
if METHOD == "TEST":
print("test:", data["mydata"])
events.registerEvent("ON_CONNECT", ON_CONNECT)
events.registerEvent("ON_RECEIVE", ON_RECEIVE)
Thread(target=CLIENT.connect, args=["HOST-IP", 15749, True]).start()
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
CrawlerCodePythonTools-1.1.7.tar.gz
(380.8 kB
view hashes)
Close
Hashes for CrawlerCodePythonTools-1.1.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5922e80b5a04d8b5975fc32b707732e67fc5467a7ac216f9a354eff1509568d7 |
|
MD5 | fa38c0c5ccf1c8343456eaa09e97239a |
|
BLAKE2b-256 | 8b5d532101ade64909543a1757fc57d5fe542188f7397ecb4621f97c023b9def |