gpt4 book ai didi

php - PHRets : Using PHP to download real estate listing photos

转载 作者:行者123 更新时间:2023-12-04 02:54:11 30 4
gpt4 key购买 nike

我正在尝试创建一个 PHP (PHrets) 脚本,用于从特定区域下载所有房地产列表信息,并将所有列表数据(CSV 文件和照片)保存在我的网络服务器上。

注意:单个列表最多可包含 20 张照片。

我正在使用 PHrets 检索 MLS 列表数据,它非常适合创建 CSV 数据。但是,我想修改此代码以循环遍历每个列表的照片并使用以下名称约定将它们下载到我的网络服务器上:MLSID-PHOTOID。

下面的错误来自代码末尾的 GetObject 循环:错误消息:HTTP 错误 500(内部服务器错误):服务器尝试满足请求时遇到意外情况。

提前致谢!

    <?php

$rets_login_url = "http://maxebrdi.rets.fnismls.com/Rets/FNISRETS.aspx/MAXEBRDI/login?&rets-version=rets/1.5";
$rets_username = "MyUser";
$rets_password = "MyPass";

// use http://retsmd.com to help determine the SystemName of the DateTime field which
// designates when a record was last modified
$rets_status_field = "L_StatusCatID";
$rets_city_field = "L_City";

// use http://retsmd.com to help determine the names of the classes you want to pull.
// these might be something like RE_1, RES, RESI, 1, etc.
//"RE_1"
$property_classes = array("LR_5");

// DateTime which is used to determine how far back to retrieve records.
// using a really old date so we can get everything
$listing_status = 1;

$listing_city = "OAKLAND";

//////////////////////////////

require_once("phrets.php");

// start rets connection
$rets = new phRETS;

echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);

if ($connect) {
echo " + Connected<br>\n";
}
else {
echo " + Not connected:<br>\n";
print_r($rets->Error());
exit;
}

foreach ($property_classes as $class) {

echo "+ Property:{$class}<br>\n";

$file_name = strtolower("property_{$class}.csv");
$fh = fopen($file_name, "w+");

$maxrows = true;
$offset = 1;
$limit = 1000;
$fields_order = array();

while ($maxrows) {

$query = "({$rets_status_field}={$listing_status}),({$rets_city_field}={$listing_city})";

// run RETS search
echo " + Query: {$query} Limit: {$limit} Offset: {$offset}<br>\n";
$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));

if ($rets->NumRows() > 0) {

if ($offset == 1) {
// print filename headers as first line
$fields_order = $rets->SearchGetFields($search);
fputcsv($fh, $fields_order);
}

// process results
while ($record = $rets->FetchRow($search)) {
$this_record = array();
foreach ($fields_order as $fo) {
$this_record[] = $record[$fo];
}
fputcsv($fh, $this_record);
}

$offset = ($offset + $rets->NumRows());

}

$maxrows = $rets->IsMaxrowsReached();
echo " + Total found: {$rets->TotalRecordsFound()}<br>\n";

$rets->FreeResult($search);
}

fclose($fh);
echo " - done<br>\n";

}

/*
//This code needs to be fixed. Not sure how to include the listing array correctly.
$photos = $rets->GetObject("Property", "Photo", $record[ListingID], "*", 1);
foreach ($photos as $photo) {
$listing = $photo['Content-ID'];
$number = $photo['Object-ID'];

if ($photo['Success'] == true) {
echo "{$listing}'s #{$number} photo is at {$photo['Location']}\n";
file_put_contents("photos/{$photo['Content-ID']}-{$photo['Object-ID']}.jpg",
$photo['Data']);
}
else {
echo "Error ({$photo['Content-ID']}-{$photo['Object-ID']}
}
}

//ERROR Message: HTTP Error 500 (Internal Server Error): An unexpected condition was //encountered while the server was attempting to fulfill the request.
*/
echo "+ Disconnecting<br>\n";
$rets->Disconnect();

最佳答案

我修改了处理每条记录的 while 循环,以获取该记录的照片。我还在 RETS 服务器上对此进行了测试。

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);
}

我发现的一件事是您在这一行上有 ListingID:

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

但是在您的搜索查询中,您将 ListingID 称为 L_ListingID。也许上面一行应该有 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));

关于php - PHRets : Using PHP to download real estate listing photos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16990495/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com