-
Notifications
You must be signed in to change notification settings - Fork 0
/
airbnb_clean.py
32 lines (27 loc) · 883 Bytes
/
airbnb_clean.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
import csv
import requests
import json
def cleanup():
with open('airbnb-listings.csv', 'r', encoding='ISO-8859-1') as fh:
reader = csv.DictReader(fh)
count = 0
total = []
for row in reader:
if count >= 500:
break
listing_url = row.get('Listing Url', None)
if listing_url:
res = requests.get(listing_url)
histories = res.history
if histories == []:
print(f"Expired url for {listing_url}")
continue
else:
total.append(row)
count += 1
print(f'Fetch successfullty for {listing_url} @ {count}')
print('All finished')
return json.dumps(total)
with open('output.json', 'w') as fh:
result = cleanup()
fh.write(result)