PHRets: Using PHP to download real estate listing photos

前端 未结 2 661
花落未央
花落未央 2021-01-20 14:54

Am a trying to create a PHP (PHrets) script that downloads all real estate listing information from a specific area and saves all of the listings data (CSV file and photos)

相关标签:
2条回答
  • 2021-01-20 15:51

    I modified your while loop that processes each record to also get the photos for that record. I also tested this on a RETS server.

    while ($record = $rets->FetchRow($search)) {
            $this_record = array();
            foreach ($fields_order as $fo) {
    
            if ($fo == 'L_ListingID') {
    
                $photos = $rets->GetObject("Property", "Photo", $record[$fo], "*", 1);
    
                foreach ($photos as $photo) {
    
                    if ($photo['Success'] == true) {
    
                         file_put_contents("photos/{$photo['Content-ID']}-{$photo['Object-ID']}.jpg", $photo['Data']);   
    
                    }   
                }
            }
          $this_record[] = $record[$fo];
        }                           
    fputcsv($fh, $this_record);    
    }
    

    One thing I found is you have ListingID on this line:

    $photos = $rets->GetObject("Property", "Photo", $record[ListingID], "*", 1);
    

    But then in your search query you refer to ListingID as L_ListingID. Maybe the above line should have L_ListingID.

    $search = $rets->SearchQuery("Property", $class, $query, array("Limit" => $limit, "Offset" => $offset, "Format" => "COMPACT", "Select" => "L_ListingID,L_Class,L_Type_,L_Status,L_AskingPrice,L_Keyword2,L_Keyword3,L_Keyword4,L_SquareFeet,L_Remarks,L_Address,L_City,L_State,LO1_OrganizationName,LA1_AgentLicenseID,LA1_UserFirstName,LA1_UserLastName,L_PictureCount", "Count" => 1));
    
    0 讨论(0)
  • 2021-01-20 15:56

    What if the last parameter of GetObject is "0" :

    $photos = $rets->GetObject("Property", "Photo", $record[$fo], "*", 1);

    in this case "1" is for retreiving the location. some servers this is switched off and return the actual image I believe - that would require a different method.

    0 讨论(0)
提交回复
热议问题