public static function one(array $friend) { static::load(); $key = Phrases::filterByColumn($friend, array('gender', 'tags'))[0]; $phrase = static::$phrases[$key]['message']; unset(static::$phrases[$key]); if (!strstr($phrase, '%s')) { return $phrase; } return sprintf($phrase, explode(' ', $friend['name'])[0]); }
public function run() { $logger = new Logger('day-wishes'); $birthdays = Facebook::getTodayBirthdays(); if (empty($birthdays)) { $logger->log('FINISH', 'No birthdays today'); return; } foreach ($birthdays as $friend) { if ($friend['form_action'] === null) { $logger->log(sprintf('%s has not form', $friend['name'])); continue; } $friend['message'] = Phrases::one($friend); $friend['inputs'][$friend['message_input']] = $friend['message']; $logger->log('PERSON', sprintf('%s is on birthday! : %s', $friend['name'], $friend['message'])); Curl::post($friend['form_action'], $friend['inputs']); sleep(rand(1, 5)); } }