# asean-lottery-companies (`0x_wzhenkai/asean-lottery-companies`)

Returns information about all lottery companies, including their provider IDs, names, and next scheduled draw dates.

- **URL**: https://beta-securitybyobscurity.apify.com/0x\_wzhenkai/asean-lottery-companies.md
- **Developed by:** [Zhen Kai](https://beta-securitybyobscurity.apify.com/0x_wzhenkai) (community)
- **Categories:** Other, Integrations, Developer tools
- **Stats:** 2 total users, 2 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

$3.00/month + usage

To use this Actor, you pay a monthly rental fee to the developer. The rent is subtracted from your prepaid usage every month after the free trial period.
You also pay for the Apify platform usage, which gets cheaper the higher Apify subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#rental-actors

# README

## ASEAN Lottery Companies Actor

This Apify actor retrieves all ASEAN lottery companies with their next draw dates from 12 different game providers across 5 ASEAN countries.

### 🎯 What it does

The actor connects to a MySQL database and fetches information about all available lottery companies, including:

- Company provider ID (PID)
- Company name
- Next scheduled draw date

### 🌏 Supported Countries & Providers

#### Malaysia (6 providers)

- **Magnum 4D** (PID: MAG)
- **Da Ma Cai 4D** (PID: DMC)
- **Sports Toto 4D** (PID: TOT)
- **Cashsweep 4D** (PID: CSP)
- **Sandakan 4D** (PID: STC)
- **Sabah 88 4D** (PID: S88)

#### Singapore (1 provider)

- **Singapore Pools 4D** (PID: SGP)

#### Cambodia (3 providers)

- **GD Lotto 4D** (PID: GDL)
- **Lucky Hari Hari 4D** (PID: LHH)
- **Perdana 4D** (PID: PDN)

#### Vietnam (1 provider)

- **Vietnam Lottery 4D** (PID: VIE)

#### Philippines (1 provider)

- **PCSO 4D Lotto** (PID: PHL)

### 📥 Input

This actor requires **no input parameters**. Simply run it to get all lottery companies.

```json
{}
```

### 📤 Output

The actor returns a JSON object with the following structure:

```json
{
  "success": true,
  "data": [
    {
      "pid": "MAG",
      "name": "Magnum",
      "next_draw_date": "20250530"
    },
    {
      "pid": "SGP", 
      "name": "Singapore Pools",
      "next_draw_date": "20250531"
    }
    // ... more companies
  ]
}
```

#### Output Fields

- **success** (boolean): Indicates if the operation was successful
- **data** (array): Array of lottery companies
  - **pid** (string): Provider ID (e.g., "MAG", "SGP")
  - **name** (string): Full company name
  - **next\_draw\_date** (string): Next draw date in YYYYMMDD format

### ⚙️ Configuration

#### Required Environment Variables

Set these environment variables in the Actor settings:

```
MYSQLHOST=your_database_host
MYSQLUSER=your_database_user
MYSQLPASSWORD=your_database_password
MYSQLDATABASE=your_database_name
MYSQLPORT=3306
```

#### Alternative Environment Variables (Fallback)

```
DB_HOST=your_database_host
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_NAME=your_database_name
DB_PORT=3306
```

### 📊 Database Requirements

The actor expects these database tables:

#### lottery\_companies

- `company_id` (INT, PRIMARY KEY)
- `pid` (VARCHAR) - Provider ID
- `name` (VARCHAR) - Company name

#### upcoming\_draws

- `company_id` (INT) - Foreign key to lottery\_companies
- `next_draw_date` (DATE/DATETIME) - Next scheduled draw
- `completed` (TINYINT) - Draw completion status (0 = not completed)

### 🚀 Usage Examples

#### Run via Apify Console

1. Go to the actor page
2. Click "Start"
3. Leave input empty `{}`
4. View results in the Dataset

#### Run via API

```bash
curl -X POST https://api.apify.com/v2/acts/YOUR_ACTOR_ID/runs \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'
```

#### Run via Apify Client (Node.js)

```javascript
const { ApifyApi } = require('apify-client');

const client = new ApifyApi({
    token: 'YOUR_API_TOKEN'
});

const run = await client.actor('YOUR_ACTOR_ID').call();
const dataset = await client.dataset(run.defaultDatasetId).listItems();
console.log(dataset.items);
```

### ⏰ Draw Schedules

#### Malaysia

- **Regular draws**: Wednesday, Saturday, Sunday at 7:00 PM
- **Special draws**: Occasionally on Tuesdays at 7:00 PM

#### Singapore

- **Draws**: Wednesday, Saturday, Sunday at 6:30 PM

#### Cambodia

- **Draws**: Daily
  - GD Lotto: 7:15 PM
  - Lucky Hari Hari: 7:45 PM
  - Perdana: 7:15 PM

#### Vietnam

- **Draws**: Daily at 11:30 AM

#### Philippines

- **Draws**: Monday, Wednesday, Friday at 9:00 PM

### 🔍 Troubleshooting

#### Common Issues

**Database Connection Failed**

- Verify database credentials
- Check network connectivity
- Ensure database accepts external connections

**No Results Returned**

- Check if lottery\_companies table has data
- Verify upcoming\_draws table has future dates
- Check database table structure

**Empty next\_draw\_date**

- Ensure upcoming\_draws table is populated
- Check date formats in database
- Verify completed field is set correctly

### 📝 Notes

- The actor only returns draws scheduled for current date or future dates
- Completed draws (completed=1) are excluded from next\_draw\_date calculation
- Date format is always YYYYMMDD for consistency
- Actor automatically handles different date formats from database

### 🔒 Security

- Use read-only database user for production
- Secure database credentials in environment variables
- Enable SSL/TLS for database connections when possible

### 📞 Support

For issues related to this actor, please check:

1. Database connectivity and credentials
2. Table structure and data
3. Environment variable configuration

### 📄 License

This actor is provided as-is for lottery data retrieval purposes.

# Actor input Schema

## Actor input object example

```json
{}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("0x_wzhenkai/asean-lottery-companies").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("0x_wzhenkai/asean-lottery-companies").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call 0x_wzhenkai/asean-lottery-companies --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=0x_wzhenkai/asean-lottery-companies",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "asean-lottery-companies",
        "description": "Returns information about all lottery companies, including their provider IDs, names, and next scheduled draw dates.",
        "version": "0.0",
        "x-build-id": "g1l3w7LgcaOTqWJEO"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/0x_wzhenkai~asean-lottery-companies/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-0x_wzhenkai-asean-lottery-companies",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/0x_wzhenkai~asean-lottery-companies/runs": {
            "post": {
                "operationId": "runs-sync-0x_wzhenkai-asean-lottery-companies",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/0x_wzhenkai~asean-lottery-companies/run-sync": {
            "post": {
                "operationId": "run-sync-0x_wzhenkai-asean-lottery-companies",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {}
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
