Skip to main content

CraftAPI, easy to use scraping and API library.

Project description

CraftAPI

CraftAPI is a simple-to-use Python library providing a set of tools for interacting with websites and retrieving various types of information, as well as utility functions for variable manipulation and time formatting.

Installation

Install the package using pip:

pip install craftllc-api

Usage

ReqTools Class

This class provides methods for web scraping and making HTTP requests.

from craftapi import ReqTools, UnknownMethod

req_tools = ReqTools()

# Get page title
title = req_tools.get_page_title("https://www.python.org/")
print(f"Page Title: {title}")

# Get all links on a page
links = req_tools.get_all_links("https://www.python.org/")
print("All Links:")
for link in links[:5]: # Print first 5 links
    print(link)

# Check HTTP status code
status_code = req_tools.check_http_status("https://www.python.org/")
print(f"HTTP Status Code: {status_code}")

# Extract all paragraphs
paragraphs = req_tools.extract_paragraphs("https://www.python.org/")
print("First Paragraph:")
if paragraphs:
    print(paragraphs[0])

# Get meta tags
meta_tags = req_tools.get_meta_tags("https://www.python.org/")
print("Meta Tags:")
for name, content in meta_tags.items():
    print(f"  {name}: {content}")

# Check SSL certificate (basic check)
ssl_status = req_tools.check_ssl_certificate("https://www.google.com/")
print(f"SSL Status: {ssl_status}")

# Save HTML content to a file
save_status = req_tools.save_html_to_file("https://www.python.org/", "python_org.html")
print(save_status)

# Extract list items
list_items = req_tools.extract_list_items("https://www.python.org/")
print("First List Item:")
if list_items:
    print(list_items[0])

# Get the first H1 tag
h1_tag = req_tools.get_first_h1("https://www.python.org/")
print(f"First H1 Tag: {h1_tag}")

# Get all script URLs
scripts = req_tools.get_all_scripts("https://www.python.org/")
print("First Script URL:")
if scripts:
    print(scripts[0])

# Extract form data
form_data = req_tools.extract_form_data("https://www.w3schools.com/html/html_forms.asp")
print("Form Data (first form):")
if form_data:
    print(form_data[0])

# Get CSS links
css_links = req_tools.get_css_links("https://www.python.org/")
print("First CSS Link:")
if css_links:
    print(css_links[0])

# Find all image URLs
image_urls = req_tools.find_all_images_url("https://www.python.org/")
print("First Image URL:")
if image_urls:
    print(image_urls[0])

# WHOIS lookup
whois_info = req_tools.whois("8.8.8.8")
print("WHOIS Info for 8.8.8.8:")
for key, value in whois_info.items():
    print(f"  {key}: {value}")

# Example of UnknownMethod exception
try:
    req_tools.find_all_images_url("https://example.com", method="INVALID")
except UnknownMethod as e:
    print(f"Caught expected exception: {e}")

Wordle Class

This class provides methods related to New York Times games, specifically Wordle.

from craftapi import Wordle

wordle_game = Wordle()

# Get today's Wordle answer
wordle_answer = wordle_game.answer
print(f"Today's Wordle Answer: {wordle_answer}")

VarTools Class

This class provides utility methods for variable inspection and time formatting.

from craftapi import VarTools

my_vars = {"name": "CraftAPI", "version": 0.1, "is_active": True}
var_tools = VarTools(my_vars)

# Get variable value
name_value = var_tools.get_var_value("name")
print(f"Value of 'name': {name_value}")

# Clean variable type
name_type = var_tools.clean_type("name")
version_type = var_tools.clean_type("version")
print(f"Type of 'name': {name_type}")
print(f"Type of 'version': {version_type}")

# Format time in seconds
formatted_time_seconds = var_tools.format_time(30)
formatted_time_minutes = var_tools.format_time(150)
formatted_time_hours = var_tools.format_time(7200)
formatted_time_days = var_tools.format_time(90000)
print(f"30 seconds: {formatted_time_seconds}")
print(f"150 seconds: {formatted_time_minutes}")
print(f"7200 seconds: {formatted_time_hours}")
print(f"90000 seconds: {formatted_time_days}")

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

craftllc_api-1.0.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

craftllc_api-1.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file craftllc_api-1.0.0.tar.gz.

File metadata

  • Download URL: craftllc_api-1.0.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for craftllc_api-1.0.0.tar.gz
Algorithm Hash digest
SHA256 665c1b59ecce0b92b7a678b4c42ababb67411daf98f0a4a306dab332c0fb66dd
MD5 8771409380f49f179d09045bb37e27a1
BLAKE2b-256 0e28d5c5f503e9769cac5ba7bfaa42cf29501fa717b30313767e9bb003cf63ac

See more details on using hashes here.

File details

Details for the file craftllc_api-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: craftllc_api-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for craftllc_api-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4b7e18bddf0245e1416c88877d6aa37a3ccd6cf48b431cc8bdc3ce8963867ed
MD5 fdbdf3778326bf764a7da04e93b8d612
BLAKE2b-256 17b6bfb75360d9ef725e1b25de7bc15b746e8fa97767644185ac35edfec1c914

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page