forked from flathunters/flathunter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (45 loc) · 1.72 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
""" Startup file for Google Cloud deployment or local webserver"""
import os
from flathunter.argument_parser import parse
from flathunter.idmaintainer import IdMaintainer
from flathunter.googlecloud_idmaintainer import GoogleCloudIdMaintainer
from flathunter.web_hunter import WebHunter
from flathunter.config import Config
from flathunter.logging import configure_logging
from flathunter.web import app
# load config
args = parse()
config_handle = args.config
if config_handle is not None:
config = Config(config_handle.name)
else:
config = Config()
if __name__ == '__main__':
# Use the SQLite DB file if we are running locally
id_watch = IdMaintainer(f'{config.database_location()}/processed_ids.db')
else:
# Load the driver manager from local cache (if chrome_driver_install.py has been run
os.environ['WDM_LOCAL'] = '1'
# Use Google Cloud DB if we run on the cloud
id_watch = GoogleCloudIdMaintainer(config)
configure_logging(config)
# initialize search plugins for config
config.init_searchers()
hunter = WebHunter(config, id_watch)
app.config["HUNTER"] = hunter
if config.has_website_config():
app.secret_key = config.website_session_key()
app.config["DOMAIN"] = config.website_domain()
app.config["BOT_NAME"] = config.website_bot_name()
else:
app.secret_key = b'Not a secret'
notifiers = config.notifiers()
if "telegram" in notifiers:
app.config["BOT_TOKEN"] = config.telegram_bot_token()
if "mattermost" in notifiers:
app.config["MM_WEBHOOK_URL"] = config.mattermost_webhook_url()
if __name__ == '__main__':
listen = config['website'].get('listen', {})
host = listen.get('host', '127.0.0.1')
port = listen.get('port', '8080')
app.run(host=host, port=port, debug=True)