Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

Commit 995e1a0

Browse files
committed
add logging function to this tool
1 parent f4ab8ef commit 995e1a0

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,6 @@ Temporary Items
194194
secret.yaml
195195
dataset/*
196196
.vscode/
197+
*.log
197198

198199
# End of https://www.toptal.com/developers/gitignore/api/python,venv,vscode

src/twitchanal/cli.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import click
2+
import logging
3+
import os
24
from twitchanal.secret.secret import save_id_secret
35
from twitchanal.collect.save import collect_data
46

@@ -37,9 +39,22 @@ def save_user(dir):
3739
help=
3840
'Whether to collect extra info like `peek viewers`, `peek channels` and so on for top games.'
3941
)
40-
def collect(dir: str, timestamp: bool, num: int, extra: bool):
42+
@click.option('--debug/--no-debug',
43+
default=False,
44+
help='Run in debug mode or not.')
45+
def collect(dir: str, timestamp: bool, num: int, extra: bool, debug: bool):
4146
""" Collect data for analysis
4247
"""
48+
try:
49+
os.remove('twitchanal.log')
50+
except OSError:
51+
pass
52+
53+
if debug:
54+
lv = logging.DEBUG
55+
else:
56+
lv = logging.INFO
57+
logging.basicConfig(filename='twitchanal.log', level=lv)
4358
collect_data(dir, timestamp, num, extra)
4459

4560

src/twitchanal/collect/fetch.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import requests
33
import time
44
import random
5+
import logging
56
from typing import List
67
from termcolor import colored, cprint
78
from twitchAPI import Twitch
@@ -97,7 +98,7 @@ def fetch_url(url: str, hint: str = ""):
9798
page = requests.get(url, headers=HAEDER)
9899
if page.status_code == 200:
99100
break
100-
print('Busy. Try again...')
101+
logging.info(url.split('/')[-1] + ' busy. Try again...')
101102
time.sleep(random.uniform(1.6, 3.0))
102103

103104
html = BeautifulSoup(page.text, 'html.parser')

src/twitchanal/collect/save.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import time
33
import pandas as pd
4+
import logging
45
from typing import NoReturn
56
from twitchAPI.twitch import Twitch
67
from twitchAPI.oauth import UserAuthenticator

0 commit comments

Comments
 (0)