Skip to content

Commit 23a6205

Browse files
authored
Add arguments for api-key and db-file (#31)
* - YouTube Data API key and database filename can now be specified on the commend line * - Update README to reflect new usage
1 parent 7116790 commit 23a6205

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Automated data collection from YouTube.
33

44
## Overview
55
This project is focused on collecting data from YouTube via the Data API.
6-
Currently, this tool will collect comment info from the provided video ID
7-
string, storing the data into an sqlite database file.
6+
Currently, this tool will collect comment info from the provided YouTube video
7+
URL and store the data into an sqlite database file.
88

99
The comment data collected includes:
1010
- author
@@ -35,17 +35,19 @@ each comment.
3535
This output below was generated by providing the video ID string of a relatively
3636
small YouTube channel.
3737
```
38-
(astro) $ python astro.py 'https://www.youtube.com/watch?v=HthY7qxV8q0' -l debug
38+
(astro) $ python astro.py 'https://www.youtube.com/watch?v=HthY7qxV8q0' -l debug --api-key <key> --db-file astro.db
3939
INFO:__init__.py:autodetect: file_cache is only supported with oauth2client<4.0.0
4040
DEBUG:discovery.py:method: URL being requested: GET https://youtube.googleapis.com/youtube/v3/commentThreads?part=snippet%2Creplies&videoId=HthY7qxV8q0&textFormat=plainText&key=<...>&alt=json
4141
DEBUG:astro.py:main: Collected data preview:
4242
comment user date PSentiment NSentiment
43-
0 Giant keys dorp twice as often in the wilderne... @selkokieli843 2024-09-23T19:06:29Z 0.0 0.25
44-
1 wilderness is the way to go here. cannon isnt ... @breaddboy 2024-09-23T18:46:20Z 0.0 0.125
45-
2 The description is about mossy keys and Bryoph... @MrRXY11 2024-09-23T16:49:55Z 0.0 0.0
46-
3 no it's not you're crazy. gaslighting isn't re... @Spookdog 2024-09-23T19:18:19Z 0.0 0.625
47-
4 Easier way imo is in the giants den with a zar... @jakeparkinson9639 2024-09-23T16:32:56Z 0.0 0.0
48-
5 First @HeyItsVarn 2024-09-23T16:05:07Z 0.0 0.0
43+
0 tbh ur voice is so relaxing i love it @johan2380 2024-09-25T21:34:21Z 0.0 0.0
44+
1 Giant keys dorp twice as often in the wilderne... @selkokieli843 2024-09-23T19:06:29Z 0.0 0.25
45+
2 Dorp lol @Nakedlollipop 2024-09-24T02:04:58Z 0.0 0.0
46+
3 wilderness is the way to go here. cannon isnt ... @breaddboy 2024-09-23T18:46:20Z 0.0 0.125
47+
4 The description is about mossy keys and Bryoph... @MrRXY11 2024-09-23T16:49:55Z 0.0 0.0
48+
5 no it's not you're crazy. gaslighting isn't re... @Spookdog 2024-09-23T19:18:19Z 0.0 0.625
49+
6 Easier way imo is in the giants den with a zar... @jakeparkinson9639 2024-09-23T16:32:56Z 0.0 0.0
50+
7 First @HeyItsVarn 2024-09-23T16:05:07Z 0.0 0.0
4951
```
5052
5153
## Background

src/astro.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def parse_args():
3333
parser.add_argument("youtube_url", type=str, help="URL to youtube video")
3434
parser.add_argument("-l", "--log", type=str, choices=['debug', 'info', 'warn', 'error'],
3535
help='Set the logging level')
36-
36+
parser.add_argument("--api-key", type=str, help="YouTube Data API key")
37+
parser.add_argument("--db-file", type=str, help="Database filename")
3738
args = parser.parse_args()
3839

3940
return args
@@ -49,8 +50,8 @@ def main():
4950

5051
# prioritize log level provided on CLI, fallback to env variable
5152
log_level = args.log if args.log else os.getenv("LOG_LEVEL")
52-
api_key = os.getenv("API_KEY")
53-
db_file = os.getenv("DB_FILE")
53+
api_key = args.api_key if args.api_key else os.getenv("API_KEY")
54+
db_file = args.db_file if args.db_file else os.getenv("DB_FILE")
5455

5556
# set up logging
5657
logger = Logger(log_level)

0 commit comments

Comments
 (0)