flaretool
flaretool is flarebrow Library.
API Doc
Attention
This library is under development and may exhibit unexpected behavior. New features will be released soon. Please stay tuned.
install
pip install flaretool
NetTool usage
NetTool Usage Document
NetTool Examples of usage
from flaretool import nettool
ip_info = nettool.get_global_ipaddr_info("192.168.0.1")
print("ip:", ip_info.ipaddr)
print("hostname:", ip_info.hostname)
print("country:", ip_info.country)
ip_address = nettool.lookup_ip("example.com")
print(ip_address)
domain_name = nettool.lookup_domain("1.1.1.1")
print(domain_name)
allowed_networks = ["192.168.0.0/24", "10.0.0.0/16"]
is_allowed = nettool.is_ip_in_allowed_networks(
"192.168.0.100", allowed_networks)
print(is_allowed)
domain_exists = nettool.domain_exists("example.com")
print(domain_exists)
japan_ips = nettool.get_japanip_list()
print(japan_ips)
is_japan = nettool.is_japan_ip("203.0.113.1")
print(is_japan)
puny_info = nettool.get_puny_code("日本語ドメイン.jp")
print("originalvalue:", puny_info.originalvalue)
print("encodevalue:", puny_info.encodevalue)
print("decodevalue:", puny_info.decodevalue)
url = "http://example.com/page.html"
user_agent = "MyScraperBot"
allowed = nettool.is_scraping_allowed(url, user_agent)
if allowed:
print(f"{url} はユーザーエージェント '{user_agent}' でのスクレイピングが許可されています。")
else:
print(f"{url} はユーザーエージェント '{user_agent}' でのスクレイピングが禁止されています。")
NetTool Command Examples of usage
flaretool nettool get_global_ipaddr_info
All methods within NetTool can be executed as commands.
Help Command
flaretool nettool -h
String utills usage
String Utills Usage Document
from flaretool import utills
from flaretool.utills import ConversionMode
value = "1234567896789"
result = utills.convert_value(value)
print(result)
value = "Hello"
result = utills.convert_value(value, ConversionMode.FULL_WIDTH)
print(result)
value = "ABCabc123"
result = utills.convert_value(
value, ascii=True, digit=False, kana=False)
print(result)
value = "ABCabc"
result = utills.convert_value(
value, ConversionMode.LOWER)
print(result)
value = "ABCabc"
result = utills.convert_value(
value, ConversionMode.UPPER)
print(result)
JapaneseHoliday Examples of usage
Holiday Usage Document
Support Range
from flaretool.holiday import JapaneseHolidays
from flaretool.holiday import JapaneseHolidaysOnline
import datetime
holidays = JapaneseHolidays()
date = datetime.date(2023, 1, 1)
is_holiday = holidays.get_holiday_name(date)
print(is_holiday)
date = "2023/1/1"
is_holiday = holidays.get_holiday_name(date)
print(is_holiday)
date = "2023/1/3"
is_holiday = holidays.get_holiday_name(date)
print(is_holiday)
start_date = datetime.date(2023, 1, 1)
end_date = datetime.date(2023, 12, 31)
holiday_list = holidays.get_holidays_in_range(start_date, end_date)
for holiday in holiday_list:
print(holiday)
holiday_list = holidays.get_holidays("2023")
for holiday in holiday_list:
print(holiday)
holiday_list = holidays.get_holidays("202305")
for holiday in holiday_list:
print(holiday)
date = datetime.date(2023, 7, 1)
business_day = holidays.get_first_business_day(date)
print(business_day)
business_day = holidays.get_first_business_day(date, 4)
print(business_day)
business_day = holidays.get_last_business_day(date)
print(business_day)
business_days = holidays.get_business_date_range(start_date, end_date)
for business_day in business_days:
print(business_day)
Decorator Examples of usage
Decorator Usage Document
from flaretool.errors import FlareToolNetworkError
from flaretool.decorators import network_required, retry, repeat, timeout, timer
@network_required
def network_access(url):
response = requests.get(url)
return response.json()
def main():
try:
network_access()
except FlareToolNetworkError:
pass
@retry(tries=3, delay=2)
def retry_function():
pass
@repeat(tries=3, interval=2)
def repeat_function():
print("repeat message")
if 複数回の実行をとめたい条件:
raise StopIteration("Stop the loop!")
pass
@timeout(5)
def my_function():
time.sleep(10)
return "Operation completed"
try:
result = my_function()
print(result)
except TimeoutError:
print("Operation timed out")
from flaretool.logger import setup_logger
logger = setup_logger(logging.DEBUG, console=True)
@timer
def example_function(x):
time.sleep(x)
return x
example_function(2)
Flarebrow Service
There are the following services available:
- Short URL service: This service allows you to shorten URLs.
- DDNS (Dynamic DNS) service: This service provides Dynamic DNS functionality.
To use this class, you need to set up an API key.
Configuration API Key
The library you are using relies on an API key to communicate with an external service. To securely store the API key, it needs to be defined either as an environment variable or in a .env
file or script setting. Please follow the instructions below:
Using an script setting:
import flaretool
flaretool.api_key = "your_api_key_here"
Using an environment variable:
Set the API key as an environment variable using the following variable name:
Example of defining an environment variable (Linux/macOS):
export API_KEY=your_api_key_here
Example of defining an environment variable (Windows):
set API_KEY=your_api_key_here
Using a .env
file:
Create a .env
file in the root directory of your project and define the API key as follows:
API_KEY=your_api_key_here
The library will read the API key from the .env
file.
You need to log in to the external service's account to obtain an API key. Be careful not to share your API key with others, and avoid committing the .env
file to a public version control system.
Please refer to the documentation of the library you are using to find the specific instructions for setting the API key and the exact name of the environment variable.
ShortURL Service Usage
ShortURL Usage Document
from flaretool.shorturl import ShortUrlService
shorturl = ShortUrlService()
result = shorturl.create_short_url("https://example.com")
print("ShortLink:", result.link)
print("OriginalURL:", result.url)
result = shorturl.get_short_url_info_list(result.id)[0]
print("ShortLink:", result.link)
print("OriginalURL:", result.url)
result.url = "https://example.com/sample"
result = shorturl.update_short_url(result)
print("ShortLink:", result.link)
print("OriginalURL:", result.url)
shorturl.delete_short_url(result)
image_data = shorturl.get_qr_code_raw_data(result)
image_path = "image.png"
with open(image_path, 'wb') as image_file:
image_file.write(image_data)
Dynamic DNS Service Usage
Dynamic DNS Usage Document
from flaretool.ddns import DdnsService
service = DdnsService()
info = service.update_ddns("example", "192.168.0.100")
print(info.status)
print(info.currentIp)
print(info.updateIp)
print(info.domain)