2022년 5월 11일 수요일

Orange3에서 LOTTO 복권 당첨결과를 받아와 저장하기

 1. 오렌지의 캔바스에 아래와같이 위젯을 배치하고 연결합니다.


2. 파이썬스크립터를 선택하고 아래내용을 복사해서 붙이고 [RUN]버튼을 선택하여 로또1등 당첨번호를 읽어 옵니다. 상당히 많은 시간이 소요되니 바람개비가 멈출때 까지 진득하니 기다리세요.
import numpy as np
import requests
from bs4 import BeautifulSoup

main_url = "https://www.dhlottery.co.kr/gameResult.do?method=byWin"
basic_url = "https://www.dhlottery.co.kr/gameResult.do?method=byWin&drwNo="

def GetLast():
resp = requests.get(main_url)
soup = BeautifulSoup(resp.text, "lxml")
result = str(soup.find("meta", {"id" : "desc", "name" : "description"})['content']) # meta
s_idx = result.find(" ")
e_idx = result.find("회")
return int(result[s_idx + 1 : e_idx])

def Crawler(s_count, e_count, fp):
for i in range(s_count , e_count + 1):
crawler_url = basic_url + str(i)
resp = requests.get(crawler_url)
soup = BeautifulSoup(resp.text, "html.parser")

text = soup.text

s_idx = text.find(" 당첨결과")
s_idx = text.find("당첨번호", s_idx) + 4
e_idx = text.find("보너스", s_idx)
num = text[s_idx:e_idx].strip().split()

s_idx = e_idx + 3
e_idx = s_idx + 3
bonus = text[s_idx:e_idx].strip()

line = str(i) + ',' + num[0] + ',' + num[1] + ',' + num[2] + ',' + num[3] + ',' +\
num[4] + ',' + num[5] + ',' + bonus
line += '\n'
fp.write(line)

istart = 1 # 시작할 차수
last = 1000 # 아래 행과 둘중에서 선택함
#last = GetLast() # 마지막 차수

fp = open('lotto_10.csv', 'w')
Crawler(istart, last, fp)
fp.close()

1회부터 1000회 까지의 내용을 읽어와서 파일로 저장하고 필요할때 불러옵니다.
 

3. 1001회차 부터 가장최근 차수는 아래와 같이 바꾸어 lotto_new.csv 로 읽어온다음

istart = 1001 # 시작할 차수
#last = 10000 # 아래 행과 둘중에서 선택함
last = GetLast() # 마지막 차수

fp = open('lotto_new.csv', 'w')
Crawler(istart, last, fp)
fp.close()

3. Concatenate Widget으로 합하여 lotto_1014.csv로 저장합니다.



댓글 없음:

tensorflow gpu 사용하기에서

 tensorflow 설치시 주의해야 한다. # Anything above 2.10 is not supported on the GPU on Windows Native python - m pip install "tensorflow<2.11...