-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimmoscout_db.py
153 lines (145 loc) · 6.81 KB
/
immoscout_db.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
149
150
151
152
153
import psycopg2
from config import config
def execute_sql_immo_DB(sqlStatement: str) -> bool:
"""
Executes a SQL Statement on the database
:param sqlStatement: the Statement that shall be executed.
:type sqlStatement: str
:return: The output of the query
"""
try:
conn = psycopg2.connect(user=config.db_username, password=config.db_password, host=config.db_host, port=config.db_port,
dbname=config.db_name)
cur = conn.cursor()
cur.execute(sqlStatement)
conn.commit()
cur.close()
conn.close()
except Exception as e:
print(e)
print(sqlStatement)
return True
def write_immoscout_kaufen_to_DB(values: dict) -> None:
"""
Inserts the given values for a buy object into the database
:param values: The values for the buy object
:type values: dict
:return: None
"""
insert_sql = (f"INSERT INTO stage.immoscout_kaufen( id, "
f"fullid, "
f"street, "
f"city, "
f"title, "
f"type, "
f"anzahl_badezimmer, "
f"anzahl_etagen, "
f"anzahl_wohnungen, "
f"anzahl_zimmer, "
f"baujahr, "
f"bruttorendite, "
f"etage, "
f"grundstueckflaeche, "
f"inseratenummer, "
f"kaufpreis, "
f"kubatur, "
f"letztes_renovationsjahr, "
f"mindestnutzflaeche, "
f"nutzflaeche, "
f"objekt_ref, "
f"objekttyp, "
f"raumhoehe, "
f"verfuegbarkeit, "
f"wohnflaeche, "
f"description) VALUES ("
f"NULLIF('{values.get('id', '''''')}', ''),"
f"NULLIF('{values.get('fullId', '''''')}', ''),"
f"NULLIF('{values.get('street', '''''')}', ''),"
f"NULLIF('{values.get('city', '''''')}', ''),"
f"NULLIF('{values.get('title', '''''')}', ''),"
f"NULLIF('{values.get('type', '''''')}', ''),"
f"NULLIF('{values.get('Anzahl Badezimmer', '''''')}', ''),"
f"NULLIF('{values.get('Anzahl Etagen', '''''')}', ''),"
f"NULLIF('{values.get('Anzahl Wohnungen', '''''')}', ''),"
f"NULLIF('{values.get('Anzahl Zimmer', '''''')}', ''),"
f"NULLIF('{values.get('Baujahr', '''''')}', ''),"
f"NULLIF('{values.get('Bruttorendite', '''''')}', ''),"
f"NULLIF('{values.get('Etage', '''''')}', ''),"
f"NULLIF('{values.get('Grundstückfläche', '''''')}', ''),"
f"NULLIF('{values.get('Inseratenummer', '''''')}', ''),"
f"NULLIF('{values.get('Kaufpreis', '''''')}', ''),"
f"NULLIF('{values.get('Kubatur', '''''')}', ''),"
f"NULLIF('{values.get('Letztes Renovationsjahr', '''''')}', ''),"
f"NULLIF('{values.get('Mindestnutzfläche', '''''')}', ''),"
f"NULLIF('{values.get('Nutzfläche', '''''')}', ''),"
f"NULLIF('{values.get('Objekt-Ref.', '''''')}', ''),"
f"NULLIF('{values.get('Objekttyp', '''''')}', ''),"
f"NULLIF('{values.get('Raumhöhe', '''''')}', ''),"
f"NULLIF('{values.get('Verfügbarkeit', '''''')}', ''),"
f"NULLIF('{values.get('Wohnfläche', '''''')}', ''),"
f"NULLIF('{values.get('description', '''''')}', ''));"
)
execute_sql_immo_DB(insert_sql)
def write_immoscout_mieten_to_DB(values: dict) -> None:
"""
Inserts the given values for a renting object into the database
:param values: The values for the renting object
:type values: dict
:return: None
"""
insert_sql = (f"INSERT INTO stage.immoscout_mieten( id, "
f"fullid, "
f"street, "
f"city, "
f"title, "
f"type, "
f"anzahl_badezimmer, "
f"anzahl_etagen, "
f"anzahl_wohnungen, "
f"anzahl_zimmer, "
f"baujahr, "
f"etage, "
f"grundstueckflaeche, "
f"inseratenummer, "
f"kubatur, "
f"letztes_renovationsjahr, "
f"miete, "
f"mindestnutzflaeche, "
f"nebenkosten, "
f"nettomiete, "
f"nutzflaeche, "
f"objekt_ref, "
f"objekttyp, "
f"raumhoehe, "
f"verfuegbarkeit, "
f"wohnflaeche, "
f"description) VALUES ("
f"NULLIF('{values.get('id', '''''')}', ''),"
f"NULLIF('{values.get('fullId', '''''')}', ''),"
f"NULLIF('{values.get('street', '''''')}', ''),"
f"NULLIF('{values.get('city', '''''')}', ''),"
f"NULLIF('{values.get('title', '''''')}', ''),"
f"NULLIF('{values.get('type', '''''')}', ''),"
f"NULLIF('{values.get('Anzahl Badezimmer', '''''')}', ''),"
f"NULLIF('{values.get('Anzahl Etagen', '''''')}', ''),"
f"NULLIF('{values.get('Anzahl Wohnungen', '''''')}', ''),"
f"NULLIF('{values.get('Anzahl Zimmer', '''''')}', ''),"
f"NULLIF('{values.get('Baujahr', '''''')}', ''),"
f"NULLIF('{values.get('Etage', '''''')}', ''),"
f"NULLIF('{values.get('Grundstückfläche', '''''')}', ''),"
f"NULLIF('{values.get('Inseratenummer', '''''')}', ''),"
f"NULLIF('{values.get('Kubatur', '''''')}', ''),"
f"NULLIF('{values.get('Letztes Renovationsjahr', '''''')}', ''),"
f"NULLIF('{values.get('Miete', '''''')}', ''),"
f"NULLIF('{values.get('Mindestnutzfläche', '''''')}', ''),"
f"NULLIF('{values.get('Nebenkosten', '''''')}', ''),"
f"NULLIF('{values.get('Nettomiete', '''''')}', ''),"
f"NULLIF('{values.get('Nutzfläche', '''''')}', ''),"
f"NULLIF('{values.get('Objekt-Ref.', '''''')}', ''),"
f"NULLIF('{values.get('Objekttyp', '''''')}', ''),"
f"NULLIF('{values.get('Raumhöhe', '''''')}', ''),"
f"NULLIF('{values.get('Verfügbarkeit', '''''')}', ''),"
f"NULLIF('{values.get('Wohnfläche', '''''')}', ''),"
f"NULLIF('{values.get('description', '''''')}', ''));"
)
execute_sql_immo_DB(insert_sql)