Skip to content

Commit d5fa841

Browse files
committed
Add comments in youtube/youtube_scratcher.py
Signed-off-by: Priyanshi Gaur <noxdot1134@gmail.com>
1 parent 6e4957d commit d5fa841

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

youtube/youtube_scratcher.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
from requests.adapters import HTTPAdapter
1717
from urllib3.util.retry import Retry
1818

19+
# Get the current working directory
1920
CWD = os.path.dirname(os.path.abspath(__file__))
21+
# Load environment variables
2022
dotenv_path = os.path.join(os.path.dirname(CWD), ".env")
2123
load_dotenv(dotenv_path)
2224

25+
# Get the current date
2326
today = dt.datetime.today()
27+
# Get the YouTube API key
2428
API_KEY = os.getenv("YOUTUBE_API_KEY")
29+
# Set up file path for CSV report
2530
DATA_WRITE_FILE = (
2631
f"{CWD}" f"/data_youtube_{today.year}_{today.month}_{today.day}.csv"
2732
)
@@ -31,13 +36,14 @@
3136

3237

3338
def get_next_time_search_interval():
34-
"""Provides the next searching interval of time for Creative Commons
39+
"""
40+
Provides the next searching interval of time for Creative Commons
3541
licensed video.
3642
3743
Yields:
38-
tuple: A tuple representing the time search interval currently dealt
39-
via 2 RFC 3339 formatted date-time values (by YouTube API Standards),
40-
and the current starting year and month of the interval.
44+
- tuple: A tuple representing the time search interval currently dealt
45+
via 2 RFC 3339 formatted date-time values (by YouTube API Standards),
46+
and the current starting year and month of the interval.
4147
"""
4248
cur_year, cur_month = 2009, 1
4349
while cur_year * 100 + cur_month <= today.year * 100 + today.month:
@@ -66,17 +72,18 @@ def get_next_time_search_interval():
6672

6773

6874
def get_request_url(time=None):
69-
"""Provides the API Endpoint URL for specified parameter combinations.
75+
"""
76+
Provides the API Endpoint URL for specified parameter combinations.
7077
7178
Args:
72-
time: A tuple indicating whether this query is related to video time
73-
occurrence, and the time interval which it would like to investigate.
74-
Defaults to None to indicate the query is not related to video time
75-
occurrence.
79+
- time: A tuple indicating whether this query is related to video time
80+
occerrence, and the time interval which it would like to investigate.
81+
Defaults to None to indicate the query is not related to video time
82+
occurrence.
7683
7784
Returns:
78-
string: A string representing the API Endpoint URL for the query
79-
specified by this function's parameters.
85+
- string: A string representing the API Endpoint URL for the query
86+
specified by this function's parameters.
8087
"""
8188
base_url = (
8289
r"https://youtube.googleapis.com/youtube/v3/search?part=snippet"
@@ -92,17 +99,18 @@ def get_request_url(time=None):
9299

93100

94101
def get_response_elems(time=None):
95-
"""Provides the metadata for query of specified parameters
102+
"""
103+
Provides the metadata for query of specified parameters
96104
97105
Args:
98-
time: A tuple indicating whether this query is related to video time
99-
occurrence, and the time interval which it would like to investigate.
100-
Defaults to None to indicate the query is not related to video time
101-
occurrence.
106+
- time: A tuple indicating whether this query is related to video time
107+
occurrence, and the time interval which it would like to investigate.
108+
Defaults to None to indicate the query is not related to video time
109+
occurrence.
102110
103111
Returns:
104-
dict: A dictionary mapping metadata to its value provided from the API
105-
query of specified parameters.
112+
- dict: A dictionary mapping metadata to its value provided from the API
113+
query of specified parameters.
106114
"""
107115
search_data = None
108116
try:
@@ -114,6 +122,7 @@ def get_response_elems(time=None):
114122
)
115123
session = requests.Session()
116124
session.mount("https://", HTTPAdapter(max_retries=max_retries))
125+
# Send GET request to YouTube API
117126
with session.get(request_url) as response:
118127
response.raise_for_status()
119128
search_data = response.json()

0 commit comments

Comments
 (0)