-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_watcher.py
114 lines (90 loc) · 2.93 KB
/
run_watcher.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
import mysreality.db as db
import mysreality.estate_reader as er
import mysreality.api as api
import mysreality.assets as assets
import mysreality.watcher as watcher
import pathlib
import time
import argparse
import logging
def filter_df(df):
df = df[df["price"] < 4500000]
is_near_external_station = (df["closest_station_km"] < 15) & (
df["closest_station_name"] != "Praha"
)
is_near_prague = (df["closest_station_km"] < 30) & (
df["closest_station_name"] == "Praha"
)
df = df[is_near_external_station | is_near_prague]
df = df[df["Plocha pozemku"] > 500]
df = df[(df["Stavba"] != "Dřevostavba") & (df["Stavba"] != "Montovaná")]
df = df[df["state_score"] > 4]
df = df[df["reaction"].isnull()] # not previously seen
return df
def setup_logging(args, main_logger_name=None):
# external_loggers = ['httpx','apscheduler.scheduler','apscheduler.executors.default']
# for logger_name in external_loggers:
# ext_logger = logging.getLogger(logger_name)
# ext_logger.setLevel(args.logLevel)
logging.basicConfig(
level=args.loglevel,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
# this logger is always info
if main_logger_name:
logger = logging.getLogger("mysreality.telegram_bot")
logger.setLevel(logging.INFO)
def setup_argparse():
parser = argparse.ArgumentParser()
parser.add_argument(
"-d",
"--debug",
help="Print lots of debugging statements",
action="store_const",
dest="loglevel",
const=logging.DEBUG,
default=logging.WARNING,
)
parser.add_argument("--root", help="Folder with estates data", required=True)
parser.add_argument(
"--interval",
help="Number of minutes between checking estates",
default=30,
type=int,
)
parser.add_argument(
"-v",
"--verbose",
help="Be verbose",
action="store_const",
dest="loglevel",
const=logging.INFO,
)
return parser
def main():
parser = setup_argparse()
args = parser.parse_args()
setup_logging(args, main_logger_name="mysreality")
root = pathlib.Path(args.root)
reactions_dir = root / "user_reactions"
reactions_db = db.ReactionsDb(reactions_dir)
estates_data_path = root / "payloads"
estate_reader = er.EstateReader(estates_data_path)
estates_api = api.EstatesAPI(reactions_db, estate_reader)
timestamp_path = root / "timestamp.txt"
timestamper = db.TimestampPersitor(timestamp_path)
queue_dir = root / "queue"
queue = db.DiscoveredQueue(queue_dir)
estates_watcher = watcher.EstateWatcher(
estates_api,
timestamper,
queue,
filter_fn=filter_df,
interval_minutes=args.interval,
)
estates_watcher.sync()
estates_watcher.watch()
while True:
time.sleep(1)
if __name__ == "__main__":
main()