Files
pyfragment/main.py
T
bohd4nx 760c853acd feat: Add Fragment API for TON topups, Telegram Premium purchases, and Stars transactions
- Implemented Fragment API with methods for TON topups, Premium gifts, and Stars purchases.
- Created configuration management using environment variables.
- Added detailed README documentation for installation, configuration, and usage.
- Developed utility classes for API client, wallet linking, and transaction processing.
- Included example usage in main.py for easy demonstration of API functionalities.
- Updated requirements.txt with necessary dependencies.
2025-11-03 05:58:34 +08:00

72 lines
2.4 KiB
Python

import asyncio
import logging
from app.methods import FragmentTon, FragmentPremium, FragmentStars
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
async def topup_ton_example():
logger.info("Starting TON topup example")
ton_client = FragmentTon()
# @bohd4nx - target username, 5 - TON amount (integer 1-1000000000 (one billion))
result = await ton_client.topup_ton("@bohd4nx", 5)
if result["success"]:
data = result["data"]
logger.info(f"TON topup successful: {data['amount']} TON sent to {data['username']}")
logger.info(f"Transaction ID: {data['transaction_id']}")
else:
logger.error(f"TON topup failed: {result['error']}")
async def buy_premium_example():
logger.info("Starting Premium purchase example")
premium_client = FragmentPremium()
# @bohd4nx - target username, 6 - months duration (3, 6, or 12 only)
result = await premium_client.buy_premium("@bohd4nx", 6)
if result["success"]:
data = result["data"]
logger.info(f"Premium purchase successful: {data['months']} months sent to {data['username']}")
logger.info(f"Transaction ID: {data['transaction_id']}")
else:
logger.error(f"Premium purchase failed: {result['error']}")
async def buy_stars_example():
logger.info("Starting Stars purchase example")
stars_client = FragmentStars()
# @bohd4nx - target username, 50 - stars amount (integer 50-1000000 (one million))
result = await stars_client.buy_stars("@bohd4nx", 50)
if result["success"]:
data = result["data"]
logger.info(f"Stars purchase successful: {data['amount']} stars sent to {data['username']}")
logger.info(f"Transaction ID: {data['transaction_id']}")
else:
logger.error(f"Stars purchase failed: {result['error']}")
async def main():
logger.info("Starting Fragment API by @bohd4nx - examples")
await topup_ton_example()
await buy_premium_example()
await buy_stars_example()
logger.info("All examples completed")
if __name__ == "__main__":
logger.info("Fragment API by @bohd4nx - Usage Examples")
logger.info("Supported username formats: @username, username")
logger.info("Limits: TON minimum 1, Premium 3/6/12 months, Stars minimum 50")
logger.info("Setup: Copy .env.example to .env and fill all fields")
asyncio.run(main())