-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
44 lines (40 loc) · 1.26 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
""" Testing the setup"""
from __future__ import print_function
import os
from operator import itemgetter
from keywords import core
# Welcome message
print("\nkeywords v1.0")
print("-----------------------------------")
print("pwd: " + os.path.realpath(__file__))
MESSAGE = "Enter the text file path you want to read:"
CONFIRMATIONMESSAGE = "Try again?(Y/N):"
RAKE = core.Rake("assets/stopwords.txt")
# Event loop
FLAG = True
while FLAG:
print("-----------------------------------")
print(MESSAGE)
FILEPATH = input()
FILECONTENT = ""
if not ".txt" in FILEPATH:
print("\nThis utility only parses .txt files.")
continue
try:
FILECONTENT = open(FILEPATH, mode='r').read()
SCORES = RAKE.run(FILECONTENT)
print("----Top 10 keywords----")
COUNT = 1
SORTEDSCORES = sorted(SCORES.items(), key=itemgetter(1))
for candidate in SORTEDSCORES:
print(candidate, SCORES[candidate])
COUNT += 1
if COUNT > 10:
break
except (OSError, IOError) as fileerror:
print("Unable to load file.Please check the filepath.")
print(CONFIRMATIONMESSAGE)
FLAG = input().lower() == "y"
print("-----------------------------------")
print("Thank you!!")
#End