Advertisement
Guest User

Untitled

a guest
Apr 7th, 2010
1,761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.43 KB | None | 0 0
  1. <?php
  2. require_once('ebay_appid.php');
  3. ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071026 Firefox/3.5');
  4.  
  5. if (empty($appid))
  6. {
  7.    echo "appid undefined.";
  8.    exit(1);
  9. }
  10.  
  11. $endpoint = "http://svcs.ebay.com/services/search/FindingService/v1?";
  12.  
  13. $consonants = array ( "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w", "y" );
  14. $vowels = array ( "a", "e", "i", "o", "u" );
  15.  
  16. $searchQuery = $consonants[mt_rand(0,17)] . $vowels[mt_rand(0,4)] . "*";
  17. $max_price = "1.00";
  18. $min_price = "0.89";
  19.  
  20. $params = array (
  21.    // the header
  22.    'OPERATION-NAME' => 'findItemsByKeywords',
  23.    'SECURITY-APPNAME' => $appid,
  24.    'SERVICE-VERSION' => '1.0.0',
  25.    'GLOBAL-ID' => 'EBAY-US',
  26.    'REST-PAYLOAD',
  27.    // the query
  28.    'keywords' => $searchQuery,
  29.    // max price filter
  30.    'itemFilter[0].name' => 'MaxPrice',
  31.    'itemFilter[0].value' => $max_price,
  32.    'itemFilter[0].paramName' => 'Currency',
  33.    'itemFilter[0].paramValue' => 'USD',
  34.    // listing type
  35.    'itemFilter[1].name' => 'ListingType',
  36.    'itemFilter[1].value' => 'Auction',
  37.    // currency
  38.    'itemFilter[2].name' => 'Currency',
  39.    'itemFilter[2].value' => 'USD',
  40.    // exclude autopay
  41.    'itemFilter[3].name' => 'ExcludeAutoPay',
  42.    'itemFilter[3].value' => 'true',
  43.    // feedback min
  44.    'itemFilter[4].name' => 'FeedbackScoreMin',
  45.    'itemFilter[4].value' => '100',
  46.    // free shipping only
  47.    'itemFilter[5].name' => 'FreeShippingOnly',
  48.    'itemFilter[5].value' => 'true',
  49.    // hide duplicates
  50.    'itemFilter[6].name' => 'HideDuplicateItems',
  51.    'itemFilter[6].value' => 'true',
  52.    // top rated only
  53.    'itemFilter[7].name' => 'TopRateSellerOnly',
  54.    'itemFilter[7].value' => 'true',
  55.    // location
  56.    'itemFilter[7].name' => 'LocatedIn',
  57.    'itemFilter[7].value' => 'US',
  58.    // max bids
  59.    'itemFilter[8].name' => 'MaxBids',
  60.    'itemFilter[8].value' => '0',
  61.    // min price filter
  62.    'itemFilter[9].name' => 'MinPrice',
  63.    'itemFilter[9].value' => $min_price,
  64.    'itemFilter[9].paramName' => 'Currency',
  65.    'itemFilter[9].paramValue' => 'USD',
  66.  
  67.    'paginationInput.entriesPerPage' => '100'
  68. );
  69.  
  70. $totalPages = 0;
  71. $page = 1;
  72. $listing = array();
  73.  
  74. do {
  75.    // adjust the page number
  76.    $params['paginationInput.pageNumber'] = $page;
  77.    // build the URL
  78.    $url = $endpoint . http_build_query($params, '', '&');
  79.    // get the data
  80.    $str = @file_get_contents($url);
  81.    if (!$str) {
  82.       echo "Failed to get URL contents\n";
  83.       break;
  84.    }
  85.    // load as xml object
  86.    $xml = simplexml_load_string($str);
  87.    // get the total number of pages and entries
  88.    if (!isset($totalPagesSet)) {
  89.       $totalPages = (int) $xml->paginationOutput->totalPages;
  90.       $totalPagesSet = "yes";
  91.    }
  92.  
  93.    if (!isset($totalEntries))
  94.       $totalEntries = (int) $xml->paginationOutput->totalEntries;
  95.  
  96.    // loop through and store the URL
  97.    foreach ($xml->searchResult->item as $item) {
  98.       //echo (string) $item->viewItemURL . "\n";
  99.       array_push($listing, (string) $item->viewItemURL);
  100.    }
  101.    // increment the page number
  102.    $page = $page + 1;
  103.  
  104.    // safety net
  105.    if ($page > 100) {
  106.       echo "Safety limit reached!\n";
  107.       break;
  108.    }
  109.  
  110.    //sleep(5);
  111.  
  112. } while ($page <= $totalPages);
  113.  
  114. if (!empty($listing)) {
  115.    echo "Today's random ebay URL item (q=$searchQuery,".count($listing)."/$totalEntries) is:\n" . $listing[mt_rand(0, count($listing) - 1)] . "\n";
  116.    return 0;
  117. }
  118.  
  119. return 1;
  120.  
  121. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement