-
Notifications
You must be signed in to change notification settings - Fork 237
/
flathunter.py
executable file
·89 lines (74 loc) · 3.03 KB
/
flathunter.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import os
import logging
import time
import yaml
from flathunter.crawl_immobilienscout import CrawlImmobilienscout
from flathunter.crawl_wggesucht import CrawlWgGesucht
from flathunter.idmaintainer import IdMaintainer
from flathunter.hunter import Hunter
__author__ = "Jan Harrie"
__version__ = "1.0"
__maintainer__ = "Nody"
__email__ = "[email protected]"
__status__ = "Production"
# init logging
if os.name == 'posix':
# coloring on linux
cyellow = '\033[93m'
cblue = '\033[94m'
coff = '\033[0m'
format = '[' + cblue + '%(asctime)s' + coff + '|' + cblue + '%(filename)-18s' + coff + '|' + cyellow + \
'%(levelname)-8s' + coff + ']: %(message)s'
else:
# else without color
format = '[%(asctime)s|%(filename)-18s|%(levelname)-8s]: %(message)s',
logging.basicConfig(
format=format,
datefmt='%Y/%m/%d %H:%M:%S',
level=logging.INFO)
__log__ = logging.getLogger(__name__)
def launch_flat_hunt(config):
searchers = [CrawlImmobilienscout(), CrawlWgGesucht()]
id_watch = IdMaintainer('%s/processed_ids.db' % os.path.dirname(os.path.abspath(__file__)))
hunter = Hunter()
hunter.hunt_flats(config, searchers, id_watch)
while config.get('loop', dict()).get('active', False):
time.sleep(config.get('loop', dict()).get('sleeping_time',60*10))
hunter.hunt_flats(config, searchers, id_watch)
def main():
# parse args
parser = argparse.ArgumentParser(description="Searches for flats on Immobilienscout24.de and wg-gesucht.de and "
"sends results to Telegram User", epilog="Designed by Nody")
parser.add_argument('--config', '-c',
type=argparse.FileType('r', encoding='UTF-8'),
default='%s/config.yaml' % os.path.dirname(os.path.abspath(__file__)),
help="Config file to use. If not set, try to use '%s/config.yaml' " %
os.path.dirname(os.path.abspath(__file__))
)
args = parser.parse_args()
# load config
config_handle = args.config
__log__.info("Using config %s" % config_handle.name)
config = yaml.load(config_handle.read())
# check config
if not config.get('telegram', dict()).get('bot_token'):
__log__.error("No telegram bot token configured. Starting like this would be meaningless...")
return
if not config.get('telegram', dict()).get('receiver_ids'):
__log__.error("No telegram receivers configured. Starting like this would be meaningless...")
return
if not config.get('urls'):
__log__.error("No urls configured. Starting like this would be meaningless...")
return
# adjust log level, if required
if config.get('verbose'):
__log__.setLevel(logging.DEBUG)
from pprint import pformat
__log__.debug("Settings from config: %s" % pformat(config))
# start hunting for flats
launch_flat_hunt(config)
if __name__ == "__main__":
main()