Skip to main content

A Python library for interacting with the MyWebLog API

Project description

pyMyweblog Python Library

pyMyweblog is a Python library for interacting with the MyWebLog API, designed to fetch objects and bookings for aviation-related data. It is intended for use in Home Assistant integrations or other Python applications requiring access to MyWebLog services.

Installation

Install the library via pip:

pip install pyMyweblog

Alternatively, for local development, clone the repository and install it in editable mode:

git clone https://github.com/faanskit/pyMyweblog.git
cd pyMyweblog
pip install -e .

Prerequisites

To use the library, you need:

  • A valid MyWebLog username and password.
  • A valid app_token for MyWebLog Mobile API

Usage

The MyWebLogClient class provides methods to interact with the MyWebLog API, such as fetching objects and bookings.

Example: Fetching Objects

from pyMyweblog.client import MyWebLogClient

# Initialize the client
client = MyWebLogClient(
    username="your_username",
    password="your_password",
    app_token="your_apptoken",
)

# Fetch objects
objects = client.getObjects()
print(objects)

# Close the session
client.close()

# Alternatively, use as a context manager
with MyWebLogClient(
    username="your_username",
    password="your_password",
    app_token="your_apptoken",
) as client:
    objects = client.getObjects()
    print(objects)

Example: Fetching Bookings

from pyMyweblog.client import MyWebLogClient

with MyWebLogClient(
    username="your_username",
    password="your_password",
    app_token="your_apptoken",
) as client:
    bookings = client.getBookings(mybookings=True, includeSun=True)
    print(bookings)

Testing the API

Before pushing any changes, please follow these steps to ensure everything works locally.

  1. Set environment variables (recommended for security):

    export MYWEBLOG_USERNAME="your_username"
    export MYWEBLOG_PASSWORD="your_password"
    export MYWEBLOG_APPTOKEN="your_apptoken"
    
  2. Run the test script:

    python scripts/test_get_objects.py
    

    This will fetch objects and print the API response in a formatted way using pprint.

Development

Setting Up the Development Environment

  1. Clone the repository:

    git clone https://github.com/faanskit/pyMyweblog.git
    cd pyMyweblog
    
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: .\venv\Scripts\activate
    
  3. Install dependencies:

    pip install -e .[dev]
    

Running Tests Locally Before Pushing

To ensure your code adheres to the standards and passes tests, follow these steps before you push your changes:

  1. Install dependencies (if not already done):

    pip install -e .[dev]
    
  2. Run format and lint checks:

    • Black: Automatically formats your code to conform to Python’s PEP 8 style.

      black .
      
    • Flake8: Lints your code for style issues, such as unused imports or incorrect indentation.

      flake8 .
      
  3. Run unit tests:

    • Pytest: Run all the tests in the tests/ directory and verify they pass.
      pytest --ignore=scripts/test_get_objects.py --ignore=scripts/test_get_balance.py
      

    If all tests pass without errors, you're good to go!

Running Unit Tests

Unit tests are located in the tests/ directory and use unittest.

python -m unittest discover tests

Modifying the Code

  • The main API client is in pyMyweblog/client.py.
  • Update app_token and ac_id in MyWebLogClient with valid values or make them configurable.
  • Add new methods to MyWebLogClient for additional API endpoints as needed.

Running Test Scripts

Test scripts are located in the scripts/ directory and use python.

Example #1: To test the GetObjects function, you can run this script:

python -m scripts.test_get_objects

Example #2: To test the GetBalance function, you can run this script:

python -m scripts.test_get_balance

Contributing

Contributions are welcome! Please submit issues or pull requests to the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.

For support, contact the maintainer at [marcus.karlsson@usa.net].

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

pymyweblog-0.0.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

pymyweblog-0.0.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pymyweblog-0.0.1.tar.gz.

File metadata

  • Download URL: pymyweblog-0.0.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for pymyweblog-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c914f6833cb2336969f47bfbb166f16cbee3883dce2703293eea246aac64800e
MD5 0f163a25a6943bdef6d3a746da5e1dc0
BLAKE2b-256 09acf352910eb4257da4fa188ee8cccbf6688cd743e4e4777d1bc08f216686fb

See more details on using hashes here.

File details

Details for the file pymyweblog-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pymyweblog-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for pymyweblog-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04c8e23e48e1ff8e85ef8828bfc32f843fa3ea2067af1255fad414ff8178712f
MD5 41fe44523137fbf3ceeab59f03384e02
BLAKE2b-256 cc01941f6b2c7967f32d7c879bf015ee1e9d0dcca759a23db1b1fd0a01ae6cbc

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