Skip to content

Commit

Permalink
[ISSUE-#23] Remove is_print_data , is_output parameter, and depre…
Browse files Browse the repository at this point in the history
…cated `crawl.py`. (#28)

* feat: remove is_print_data and is_output parameter

* feat: deprecated crawl.py
  • Loading branch information
stu01509 authored Aug 15, 2023
1 parent b58d04f commit ca46af7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 145 deletions.
32 changes: 4 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ print(result)
from TaiwanLottery import TaiwanLotteryCrawler

lottery = TaiwanLotteryCrawler()
result = lottery.super_lotto(False, False, ['112', '6'])
result = lottery.super_lotto(['112', '6'])
print(result)
```

Expand All @@ -92,7 +92,7 @@ print(result)
from TaiwanLottery import TaiwanLotteryCrawler

lottery = TaiwanLotteryCrawler()
result = lottery.lotto649(False, False, ['112', '6'])
result = lottery.lotto649(['112', '6'])
print(result)
```

Expand All @@ -102,7 +102,7 @@ print(result)
from TaiwanLottery import TaiwanLotteryCrawler

lottery = TaiwanLotteryCrawler()
result = lottery.daily_cash(False, False, ['112', '6'])
result = lottery.daily_cash(['112', '6'])
print(result)
```

Expand All @@ -112,31 +112,7 @@ print(result)
from TaiwanLottery import TaiwanLotteryCrawler

lottery = TaiwanLotteryCrawler()
result = lottery.lotto1224(False, False, ['112', '6'])
print(result)
```

---

### 參數設定

關閉 Terminal 顯示

```python
from TaiwanLottery import TaiwanLotteryCrawler

lottery = TaiwanLotteryCrawler()
result = lottery.lotto649(False)
print(result)
```

儲存開獎結果成 JSON 檔案

```python
from TaiwanLottery import TaiwanLotteryCrawler

lottery = TaiwanLotteryCrawler()
result = lottery.lotto649(False, True)
result = lottery.lotto1224(['112', '6'])
print(result)
```

Expand Down
42 changes: 14 additions & 28 deletions TaiwanLottery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TaiwanLotteryCrawler():
no_data = '查無資料'

# 威力彩
def super_lotto(self, is_print_data=True, is_output=False, back_time=[utils.get_current_republic_era(), utils.get_current_month()]):
def super_lotto(self, back_time=[utils.get_current_republic_era(), utils.get_current_month()]):
URL = 'https://www.taiwanlottery.com.tw/Lotto/SuperLotto638/history.aspx'
title = '威力彩_' + str(back_time[0]) + '_' + str(back_time[1])

Expand Down Expand Up @@ -66,14 +66,10 @@ def super_lotto(self, is_print_data=True, is_output=False, back_time=[utils.get_
logging.warning(self.no_data + title)
return

if is_print_data:
utils.print_to_table(title, datas)
if is_output:
utils.output_to_json(title, datas)
return datas

# 大樂透
def lotto649(self, is_print_data=True, is_output=False, back_time=[utils.get_current_republic_era(), utils.get_current_month()]):
def lotto649(self, back_time=[utils.get_current_republic_era(), utils.get_current_month()]):
URL = 'https://www.taiwanlottery.com.tw/Lotto/Lotto649/history.aspx'
title = '大樂透_' + str(back_time[0]) + '_' + str(back_time[1])

Expand Down Expand Up @@ -126,14 +122,10 @@ def lotto649(self, is_print_data=True, is_output=False, back_time=[utils.get_cur
logging.warning(self.no_data + title)
return

if is_print_data:
utils.print_to_table(title, datas)
if is_output:
utils.output_to_json(title, datas)
return datas

# 今彩539
def daily_cash(self, is_print_data=True, is_output=False, back_time=[utils.get_current_republic_era(), utils.get_current_month()]):
def daily_cash(self, back_time=[utils.get_current_republic_era(), utils.get_current_month()]):
URL = 'https://www.taiwanlottery.com.tw/Lotto/Dailycash/history.aspx'
title = '今彩539_' + str(back_time[0]) + '_' + str(back_time[1])

Expand Down Expand Up @@ -183,14 +175,11 @@ def daily_cash(self, is_print_data=True, is_output=False, back_time=[utils.get_c
if len(datas) == 0:
logging.warning(self.no_data + title)
return
if is_print_data:
utils.print_to_table(title, datas)
if is_output:
utils.output_to_json(title, datas)

return datas

# 雙贏彩
def lotto1224(self, is_print_data=True, is_output=False, back_time=[utils.get_current_republic_era(), utils.get_current_month()]):
def lotto1224(self, back_time=[utils.get_current_republic_era(), utils.get_current_month()]):
URL = 'https://www.taiwanlottery.com.tw/Lotto/Lotto1224/history.aspx'
title = '雙贏彩_' + str(back_time[0]) + '_' + str(back_time[1])

Expand Down Expand Up @@ -240,36 +229,33 @@ def lotto1224(self, is_print_data=True, is_output=False, back_time=[utils.get_cu
if len(datas) == 0:
logging.warning(self.no_data + title)
return
if is_print_data:
utils.print_to_table(title, datas)
if is_output:
utils.output_to_json(title, datas)

return datas

# 威力彩歷史查詢
def super_lotto_back(self, is_print_data=True, is_output=True, back_month='0'):
def super_lotto_back(self, back_month='0'):
for i in range(int(back_month), -1, -1):
time.sleep(random.random())
self.super_lotto(is_print_data, is_output, utils.month_diff(i))
self.super_lotto(utils.month_diff(i))
logging.debug(str(utils.month_diff(i)[0]) + '_' + str(utils.month_diff(i)[1]))

# 大樂透歷史查詢
def lotto649_back(self, is_print_data=True, is_output=True, back_month='0'):
def lotto649_back(self, back_month='0'):
for i in range(int(back_month), -1, -1):
time.sleep(random.random())
self.lotto649(is_print_data, is_output, utils.month_diff(i))
self.lotto649(utils.month_diff(i))
logging.debug(str(utils.month_diff(i)[0]) + '_' + str(utils.month_diff(i)[1]))

# 今彩539歷史查詢
def daily_cash_back(self, is_print_data=True, is_output=True, back_month='0'):
def daily_cash_back(self, back_month='0'):
for i in range(int(back_month), -1, -1):
time.sleep(random.random())
self.daily_cash(is_print_data, is_output, utils.month_diff(i))
self.daily_cash(utils.month_diff(i))
logging.debug(str(utils.month_diff(i)[0]) + '_' + str(utils.month_diff(i)[1]))

# 雙贏彩歷史查詢
def lotto1224_back(self, is_print_data=True, is_output=True, back_month='0'):
def lotto1224_back(self, back_month='0'):
for i in range(int(back_month), -1, -1):
time.sleep(random.random())
self.lotto1224(is_print_data, is_output, utils.month_diff(i))
self.lotto1224(utils.month_diff(i))
logging.debug(str(utils.month_diff(i)[0]) + '_' + str(utils.month_diff(i)[1]))
85 changes: 0 additions & 85 deletions crawl.py

This file was deleted.

8 changes: 4 additions & 4 deletions tests/test_lottery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_super_lotto():
lottery = TaiwanLotteryCrawler()

# When user get the 威力彩 2023-06 result without print and output to json
super_lotto_result = lottery.super_lotto(False, False, [112, 6])
super_lotto_result = lottery.super_lotto([112, 6])

# Then the super_lotto_result should be equal to test result
assert super_lotto_result == [
Expand All @@ -28,7 +28,7 @@ def test_lotto649():
lottery = TaiwanLotteryCrawler()

# When user get the 大樂透 2023-06 result without print and output to json
lotto649_result = lottery.lotto649(False, False, [112, 6])
lotto649_result = lottery.lotto649([112, 6])

# Then the lotto649_result should be equal to test result
assert lotto649_result == [
Expand All @@ -49,7 +49,7 @@ def test_daily_cash():
lottery = TaiwanLotteryCrawler()

# When user get the 今彩539 2023-06 result without print and output to json
daily_cash_result = lottery.daily_cash(False, False, [112, 6])
daily_cash_result = lottery.daily_cash([112, 6])

# Then the daily_cash_result should be equal to test result
assert daily_cash_result == [
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_lotto1224():
lottery = TaiwanLotteryCrawler()

# When user get the 雙贏彩 2023-06 result without print and output to json
lotto1224_result = lottery.lotto1224(False, False, [112, 6])
lotto1224_result = lottery.lotto1224([112, 6])

# Then the lotto1224_result should be equal to test result
assert lotto1224_result == [
Expand Down

0 comments on commit ca46af7

Please sign in to comment.