[3/n] click-ify add dump images command
run with poetry run python main.py --step dump_images
This commit is contained in:
parent
c2196c15c1
commit
70e8ef9f95
2 changed files with 36 additions and 24 deletions
|
|
@ -3,29 +3,39 @@ from urllib.request import urlretrieve
|
|||
from tqdm import tqdm
|
||||
from data_access import Listing
|
||||
|
||||
for listing in tqdm(Listing.get_all_listings()):
|
||||
with open(listing.path_detail_json()) as f:
|
||||
detail = json.load(f)
|
||||
|
||||
# for photo in detail["property"]["photos"]:
|
||||
# url = photo["maxSizeUrl"]
|
||||
# picname = url.split("/")[-1]
|
||||
# order = photo["order"]
|
||||
# p = listing.path_pic_file(order, picname)
|
||||
# if p.exists():
|
||||
# continue
|
||||
# tqdm.write(str(p))
|
||||
# urlretrieve(url, p)
|
||||
def dump_images():
|
||||
for listing in tqdm(Listing.get_all_listings()):
|
||||
with open(listing.path_detail_json()) as f:
|
||||
detail = json.load(f)
|
||||
|
||||
for photo in detail["property"]["floorplans"]:
|
||||
url = photo["url"]
|
||||
picname = url.split("/")[-1]
|
||||
order = photo["order"]
|
||||
p = listing.path_floorplan_file(order, picname)
|
||||
if p.exists():
|
||||
continue
|
||||
tqdm.write(str(p))
|
||||
try:
|
||||
urlretrieve(url, p)
|
||||
except:
|
||||
tqdm.write(f"404 for {url}")
|
||||
# for photo in detail["property"]["photos"]:
|
||||
# url = photo["maxSizeUrl"]
|
||||
# picname = url.split("/")[-1]
|
||||
# order = photo["order"]
|
||||
# p = listing.path_pic_file(order, picname)
|
||||
# if p.exists():
|
||||
# continue
|
||||
# tqdm.write(str(p))
|
||||
# urlretrieve(url, p)
|
||||
|
||||
for photo in detail["property"]["floorplans"]:
|
||||
url = photo["url"]
|
||||
picname = url.split("/")[-1]
|
||||
order = photo["order"]
|
||||
p = listing.path_floorplan_file(order, picname)
|
||||
if p.exists():
|
||||
continue
|
||||
tqdm.write(str(p))
|
||||
try:
|
||||
urlretrieve(url, p)
|
||||
except:
|
||||
tqdm.write(f"404 for {url}")
|
||||
|
||||
|
||||
def main():
|
||||
dump_images()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue