Skip to content

rich-automation/lotto-module

Repository files navigation

@rich-automation/lotto

npm
ci
codecov

@rich-automation/lotto는 headless browser를 활용해 JS 환경에서 로또를 자동으로 구매할 수 있는 인터페이스를 제공합니다.

설치

# npm
npm install @rich-automation/lotto

# yarn
yarn add @rich-automation/lotto

준비 사항

  1. 내부적으로 Playwright 또는 Puppeteer를 사용하므로, Chromium이 사전에 설치되어 있어야 합니다. (링크)
  2. 구매는 동행복권 사이트에서 진행되며, 예치금 충전 기능은 없으므로 미리 계정에 예치금을 충전해두어야 합니다.

사용법

기본 설정

import { LottoService } from '@rich-automation/lotto';
import { chromium } from 'playwright';
import puppeteer from 'puppeteer';

// playwright 로 시작, 모든 기능 사용 가능
const lottoService = new LottoService({
  controller: chromium // puppeteer
});

// puppeteer 로 시작, 모든 기능 사용 가능
const lottoService = new LottoService({
  controller: puppeteer
});

// API 모드로 시작, check / getCheckWinningLink 기능만 사용 가능
const lottoService = new LottoService({
  controller: 'api'
});

옵션 설명:

  • controller: (필수) puppeteer, playwright 모듈 또는 "api"
  • headless: 기본값 false
  • defaultViewport: 기본값 { width: 1080, height: 1024 }
  • logLevel: 기본값 2 (NONE = -1, ERROR = 0, WARN = 1, INFO = 2, DEBUG = 3)
import { LottoService, LogLevel } from '@rich-automation/lotto';

const lottoService = new LottoService({
  controller: chromium,
  headless: true,
  defaultViewport: { width: 1280, height: 720 },
  logLevel: LogLevel.DEBUG
});

로또 구매

const ID = '<YOUR_ID>';
const PWD = '<YOUR_PASSWORD>';

await lottoService.signIn(ID, PWD);

const numbers = await lottoService.purchase(5);

console.log(numbers); // [[ 1, 14, 21, 27, 30, 44 ],[ 4, 5, 27, 29, 40, 44 ],[ 9, 18, 19, 24, 38, 42 ],[ 4, 6, 13, 20, 38, 39 ],[ 8, 9, 10, 19, 32, 40 ]]

당첨 확인

이번 회차 확인:

import { getLastLottoRound } from '@rich-automation/lotto';

const numbers = [
  [1, 2, 3, 4, 5, 6],
  [5, 6, 7, 8, 9, 10]
];

const currentRound = getLastLottoRound();

const result = await lottoService.check(numbers, currentRound);

console.log(result); // [{rank:1,matchedNumbers:[1,2,3,4,5,6]},{rank:5,matchedNumbers:[5,6]]

다음 회차 링크 생성:

import { getNextLottoRound } from '@rich-automation/lotto';

const nextRound = getNextLottoRound();
const link = lottoService.getCheckWinningLink(numbers, nextRound);

console.log(link); // "https://dhlottery.co.kr/qr.do?method=winQr&v=1071q010203040506q050607080910";

API

signIn(id: string, password: string): Promise<string>

동행복권 로그인, 성공 시 로그인 쿠키 반환

signInWithCookie(cookies: string): Promise<string>

쿠키 기반 로그인

purchase(amount?: number): Promise<number[][]>

로또 번호 자동 구매 (1~5 게임)

check(numbers: number[][], round?: number): Promise<{ rank:number; matchedNumbers:number[] }[]>

(API) 당첨 결과 확인

getCheckWinningLink(numbers: number[][], round?: number): string

(API) 당첨 확인 링크 생성

destroy(): Promise<void>

브라우저 인스턴스 종료

About

module for lotto

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •