-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
148 lines (109 loc) · 4.63 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import sys
import time
from globals.global_imports import *
from crawler.crawler import *
from DataParsing.KeywordExtraction import *
from DataParsing.URLParsing import *
from DB.UrlInterface import *
from DB.alchemy import *
from PyQt4 import QtGui
from globals.settings import settings
from htmlExtraction.GenerateStatistics import *
from ResultGeneration.ResultGenerator import *
import gui.MainWindow
__version__ = "0.1"
USAGE = "%prog [options] <url>"
VERSION = "%prog v" + __version__
LOG_LEVEL = logging.INFO
def correctURL(url):
''' url: String '''
if (len(url) > 8):
index_http = find(url, "http://", 0, 7)
index_https = find(url, "http://", 0, 8)
if (index_http == -1 and index_https == -1):
url = "http://" + url
return url
def parse_options():
"""parse_options() -> opts, args
Parse any command-line options given returning both
the parsed options and arguments.
"""
parser = optparse.OptionParser(usage=USAGE, version=VERSION)
parser.add_option("-q", "--quiet",
action="store_true", default=False, dest="quiet",
help="Enable quiet mode")
parser.add_option("-l", "--links",
action="store_true", default=False, dest="links",
help="Get links for specified url only")
parser.add_option("-d", "--depth",
action="store", type="int", default=3, dest="depth_limit",
help="Maximum depth to traverse")
parser.add_option("-c", "--confine",
action="store", type="string", dest="confine",
help="Confine crawl to specified prefix")
parser.add_option("-x", "--exclude", action="append", type="string",
dest="exclude", default=[], help="Exclude URLs by prefix")
parser.add_option("-L", "--show-links", action="store_true", default=False,
dest="out_links", help="Output links found")
parser.add_option("-s", "--show-urls", action="store_true", default=False,
dest="out_urls", help="Output URLs found")
parser.add_option("-D", "--dot", action="store_true", default=False,
dest="out_dot", help="Output Graphviz dot file")
parser.add_option("-K", "--keyword_parse", action="store_true", default=False,
dest="keyword_parse", help="Parse Keywords from Excel")
parser.add_option("-U", "--url_parse", action="store_true", default=False,
dest="url_parse", help="Parse URL's from Excel")
parser.add_option("--crawler", action="store_true", default=False,
dest="run_crawler", help="Run the crawler")
parser.add_option("--stats", action="store_true", default=False,
dest="run_stats", help="Generate the statistics")
parser.add_option("--results", action="store_true", default=False,
dest="results", help="Generate the results")
opts, args = parser.parse_args()
if opts.out_links and opts.out_urls:
parser.print_help(sys.stderr)
parser.error("options -L and -u are mutually exclusive")
return opts, args
def showDB(db, className):
print "Showing DB: %s" % className
objs = db.session.query(className).all()
for obj in objs:
print obj
def main():
opts, args = parse_options()
settings.opts = opts
app = QtGui.QApplication(sys.argv)
# mainWindow = gui.MainWindow.MainWindow(settings.version())
# mainWindow.show()
if opts.keyword_parse:
createKeywordDB()
exit()
if opts.url_parse:
createUrlDB()
exit()
# showDB(getKeywordDB(), ServiceLine1)
if (opts.run_crawler):
# crawlerThread = CrawlerThread(opts)
# crawlerThread.start()
while True:
print "Waiting for URL's to Crawl"
CrawlerMain(opts)
time.sleep(10)
keywordDB = getKeywordDB()
urlDB = getUrlDB()
if (opts.run_stats):
#statisticsThread = GenerateStatisticThread()
#statisticsThread.start()
while True:
print "Waiting for URL's to Analyze"
GenerateStatisticsMain(urlDB, keywordDB)
time.sleep(10)
if (opts.results):
ResultGeneratorMain()
# showDB(getUrlDB(), Company)
# exit()
# Test the keyword parsing
# KeywordParse.KeywordParseMain()
# showDB(getUrlDB(), URL)
if __name__ == "__main__":
main()