-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataFormatter.py
49 lines (43 loc) · 2 KB
/
dataFormatter.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
class DataFormatter:
@staticmethod
def format_trulia_data(data, date) -> None:
with open('data.txt', 'w') as data_file:
data_file.write(data)
with open(f'trulia-listings-{date[:10]}.txt', 'w') as listings_file:
with open('data.txt', 'r+') as data_file:
for line in data_file.readlines():
if line.startswith('NEW'):
continue
if line.startswith('$'):
listings_file.write('\n')
listings_file.write(line)
else:
listings_file.write(line)
@staticmethod
def format_realtor_dot_com_data(data, date) -> None:
with open('data.txt', 'w') as data_file:
data_file.write(data)
with open(f'realtor-listings-{date[:10]}.txt', 'w') as listings_file:
with open('data.txt', 'r+') as data_file:
for line in data_file.readlines():
if line.startswith('NEW') or line.startswith('Brokered') or line.startswith('Email'):
continue
if line.startswith('For') or line.startswith('Pending') or line.startswith('Contingent'):
listings_file.write('\n')
listings_file.write(line)
else:
listings_file.write(line)
if line.startswith('Previous'):
break
@staticmethod
def format_homes_dot_com_data(data, date) -> None:
with open('data.txt', 'w') as data_file:
data_file.write(data)
with open(f'homes-listings-{date[:10]}.txt', 'w') as listings_file:
with open('data.txt', 'r+') as data_file:
for line in data_file.readlines():
if line.startswith('-'):
listings_file.write('\n')
continue
else:
listings_file.write(line)