Posted By

swizardb on 04/01/18


Tagged

1 snippet - ATG


Versions (?)

SNIPPET 1


 / Published in: PHP
 

SNIPPET 1 - ATG

  1. if($website_crawled[0]->API_available) {
  2. $client = new \GuzzleHttp\Client();
  3. switch (TRUE)
  4. {
  5. // COMMENT 1
  6. case ($website_crawled[0]->website_address=='https://www.meetup.com' && $feature == 'meetup') :
  7. // COMMENT 2
  8. preg_match('/https:\/\/(.*?)\/(.*?)\/events\/([\w]+)/', $import_url[0]->url, $domain);
  9. if ($domain[3] == 'calendar') {
  10. // COMMENT 3
  11. DB::table('admin_url_crawled')
  12. ->where('id', $import_url[0]->id)
  13. ->update(['imported' => '0']);
  14. return 0;
  15. }
  16.  
  17. // COMMENT 4
  18. $res = $client->get('https://api.meetup.com/'.$domain[2].'/events/'.$domain[3].'/?key=184f2b');
  19.  
  20. // COMMENT 5
  21. if ($res->getStatusCode() == 200) {
  22.  
  23. // COMMENT 6
  24. $json_res = json_decode($res->getBody(), true);
  25.  
  26. if (!(isset($json_res['venue']) )) {
  27. DB::table('admin_url_crawled')
  28. ->where('id', $import_url[0]->id)
  29. ->update(['imported' => '0']);
  30. return 0;
  31. }
  32.  
  33.  
  34. $meetup = new meetup_model;
  35. $meetup->user_id_fk = '1';
  36. $meetup->title = $json_res['name'];
  37. $meetup->venue = $json_res['venue']['name'].', '.$json_res['venue']['address_1'].', '.$json_res['venue']['city'];
  38. $meetup->contact_name = $json_res['group']['name'];
  39. $meetup->latitude = $json_res['venue']['lat'];
  40. $meetup->longitude = $json_res['venue']['lon'];
  41. $meetup->location = $json_res['venue']['city'];
  42. $meetup->start_date = ($json_res['local_date']);
  43. $meetup->start_time = $json_res['local_time'];
  44. $meetup->description = $json_res['description'] . '<p><a href="' . $import_url[0]->url . '" target="_blank">See original post on Meetup.com</a></p>';
  45. $meetup->status = '0'; //Insert Meetup into DB as unpublished post
  46. $meetup->save();
  47. $meetup_id_fk = $meetup->id;
  48.  
  49. // COMMENT 7
  50. $list = DB::table('admin_url_crawled')
  51. ->where('id', $import_url[0]->id)
  52. ->update([
  53. 'imported' => '0',
  54. 'feature_id_fk' => $meetup_id_fk,
  55. ]);
  56.  
  57. } else {
  58. throw new \Exception("API did not return 200, execute catch/scrape");
  59. }
  60.  
  61. break;
  62.  
  63. // REST CODE NOT AVAILABLE

Report this snippet  

You need to login to post a comment.