-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
104 lines (83 loc) · 2.73 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import sys
import argparse
import json
import shutil
import asyncio
import tkinter as tk
from tkinter import filedialog
import bot
import data_parser
def load_config(configFileName = "config.json", exampleFileName = "example_config.json"):
if not os.path.isfile(configFileName):
if os.path.isfile(exampleFileName):
shutil.copyfile(exampleFileName, configFileName)
print("Please fill out the file '%s', then re-run the program" % configFileName)
else:
print("ERROR: Config and example config files are missing!")
return None
config = {}
with open(configFileName, 'r') as configFile:
config = json.load(configFile)
return config
def main():
config = load_config()
if config != None:
while True:
choice = get_user_input()
print("You chose %s!" % choice)
if choice == "R":
print("Running bot...\n")
bot.run_bot(config)
break
elif choice == "P":
print("Parsing Dataset...\n")
parse_csv(config)
elif choice == "T":
print("Training bot...\n")
bot.train_bot(config)
elif choice == "Q":
break
input("Press Enter to exit...")
def parse_csv(config):
parseConfig = config["parsing"]
## Promp user for dataset CSV file
print("\nPlease choose a CSV file to parse...")
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
if not file_path.endswith(".csv"):
print("File must be a CSV file!")
else:
try:
data_parser.parse_csv(file_name = file_path,
out_name = parseConfig["out_file_name"],
line_limit = parseConfig["line_limit"],
replace_YT = parseConfig["replace_youtube_links"],
include_attachments = parseConfig["include_attachments"])
except Exception as e:
print("Error parsing CSV: ")
print(e)
def get_user_input():
options = {
"1" : "R",
"2" : "P",
"3" : "T",
"4" : "Q"
}
while True:
print("\nPlease select an option:\n")
print("1 - (R)un Bot")
print("2 - (P)arse Dataset")
print("3 - (T)rain Bot using Parsed Dataset")
print("4 - (Q)uit")
choice = input("\nYour choice: ").upper()[0]
print()
if choice in options:
return options[choice]
elif choice in options.values():
return choice
else:
print("Invalid input!\n")
if __name__ == "__main__":
main()