dhapi

repository·main·Indexed 42 days ago

https://github.com/roeniss/dhlottery-api

An unofficial API and CLI wrapper for the Donghaeng Lottery (동행복권) website. It allows users to purchase Lotto 6/45 tickets in automatic, manual, and semi-automatic modes, check account balances, view purchase history, and manage deposit virtual accounts directly from the terminal.

Tokens
4.7K
Snippets
26
Records
30
Agent score
54%

What's inside dhapi

  1. Configure multiple profiles in `~/.dhapi/credentials`

    main

    Profile information is stored in a TOML file located at ~/.dhapi/credentials. You can manually edit this file to add or modify multiple accounts. Each section represents a profile name.

    To use a specific profile, pass it via the -p flag in your commands.

    [default]
    username = "dhlotter_id"
    password = "****"
    
    [another_profile]
    username = "dhlotter_second_id"
    password = "****"
  2. Use the dhapi CLI

    main

    The dhapi command-line interface allows you to manage your Donghaeng Lottery account, check balances, and purchase Lotto 6/45 tickets.

    Common global options available for most commands:

    • -p, --profile: Specify which profile to use (defaults to default).
    • -d, --debug: Enable debug logging and detailed exception reporting.
    # Example of general usage pattern
    dhapi buy-lotto645 --profile my-profile --debug
  3. Troubleshoot main.py execution issues

    main

    If main.py fails to execute, you may need to explicitly set the PYTHONPATH to ensure the module structure is correctly recognized. Run the command from the parent directory of src.

    cd ..
    PYTHONPATH=./src/ python3 src/dhapi/main.py buy_lotto645 -q
  4. Response body schema for Lottery645

    main

    A successful Lottery645 purchase returns a JSON object containing login status and a result object. The arrGameChoiceNum array contains strings representing the game choices, where the suffix indicates the selection type: 1 for Manual, 2 for Combine, and 3 for Automatic.

    {
        "loginYn": "Y",
        "result": {
            "oltInetUserId": "00NNNNNNN",
            "issueTime": "hh:mm:ss",
            "issueDay": "yyyy/MM/dd",
            "resultCode": "100",
            "barCode4": "nnnnn",
            "barCode5": "nnnnn",
            "barCode6": "nnnnn",
            "barCode1": "nnnnn",
            "barCode2": "nnnnn",
            "barCode3": "nnnnn",
            "resultMsg": "SUCCESS",
            "buyRound": "950",
            "arrGameChoiceNum": [
                "A|nn|nn|nn|nn|nn|nn3",  # Manual: 1, Combine: 2, Automatic: 3
                "B|nn|nn|nn|nn|nn|nn3",
                "C|nn|nn|nn|nn|nn|nn3"
            ],
            "weekDay": "월",
            "payLimitDate": None,
            "drawDate": None,
            "nBuyAmount": 3000
        }
    }
  5. Request body schema for Lottery645

    main

    When interacting with the Lottery645 purchase functionality, the request body requires specific fields. Note that direct is not strictly required for operation, and ROUND_DRAW_DATE or WAMT_PAY_TLMT_END_DT can be omitted.

    data = {
        "round": 777,
        "direct": "172.17.20.52",  # Not strictly required
        "nBuyAmount": str(1000 * 3),
        "param": '[{"genType":"0","arrGameChoiceNum":null,"alpabet":"A"},{"genType":"0","arrGameChoiceNum":null,"alpabet":"B"},{"genType":"0","arrGameChoiceNum":null,"alpabet":"C"}]',
        # "ROUND_DRAW_DATE": "2021/06/12",  # Can be omitted
        # "WAMT_PAY_TLMT_END_DT": "2022/06/13",  # Can be omitted
        "gameCnt": 3,
    }
  6. Set up virtual account for deposit (`assign-virtual-account`)

    main

    Automates the process of selecting a deposit amount for your assigned personal virtual account.

    Note: This command only prepares the setting on the website; you must still perform the actual bank transfer manually. The 'Quick Recharge' (간편 충전) feature is not implemented.

  7. Buy Lotto 6/45 (`buy-lotto645`)

    main

    Purchase Lotto 6/45 tickets. Supports automatic, manual, and semi-automatic modes. You can purchase up to 5 tickets at a time. Note that the Donghaeng Lottery policy limits purchases to a maximum of 5 tickets per week.

    Use the -y flag to enable automatic mode (purchasing 5 tickets) and skip the confirmation step.

    dhapi buy-lotto645 -y
  8. Assign a virtual account for deposits

    main

    Use assign_virtual_account to set up a virtual account for depositing funds. The CLI will output the account details, and you must manually deposit the specified amount into that account.

    Arguments:

    • amount: The amount to deposit. Supported values: 5000, 10000, 20000, 30000, 50000, 100000, 200000, 300000, 500000, 700000, 1000000 (Note: The help text suggests these specific increments).
    dhapi assign-virtual-account 50000