Skip to content

Commit

Permalink
Added command line parser
Browse files Browse the repository at this point in the history
  • Loading branch information
leoreinmann committed Apr 8, 2023
1 parent 3b205a1 commit 72be123
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
11 changes: 11 additions & 0 deletions arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import argparse

parser = argparse.ArgumentParser(description='App scans through a directory and stores metadata of .mkv files in MySQL database')
parser.add_argument('database_name', type=str, help='the name of the database')
parser.add_argument('database_user', type=str, help='the user to connect to the database')
parser.add_argument('database_password', type=str, help='the password to connect to the database')
parser.add_argument('folder', type=str, help='the folder containing the .mkv files')

args = parser.parse_args()

# access the arguments using args.database_name, args.database_user, args.database_password, and args.folder
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import os
import json
import sql_connection
import ast
import arguments


def main():
rootdir = '/home/host/movies'
rootdir = arguments.args.folder

for subdir, dirs, files in os.walk(rootdir):

name = str(subdir.rsplit('/', 1)[-1]) # Title (YEAR)
title = ''
year = ''
Expand All @@ -32,8 +34,6 @@ def main():

dict_audio_data = json.loads(a_str)

print(dict_audio_data["name"])

dict_data_audio_list.append(dict_audio_data)

for v in video:
Expand Down
7 changes: 4 additions & 3 deletions sql_connection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import mysql.connector
import json
import arguments

def connect_to_database():
return mysql.connector.connect(
host="localhost",
user="movie",
password="1234",
database="moviedb"
user=arguments.args.database_user,
password=arguments.args.database_password,
database=arguments.args.database_name
)

def insert_movie(title, video_data, audio_data_list):
Expand Down

0 comments on commit 72be123

Please sign in to comment.