Ejemplo n.º 1
0
function updateTwitterCache($cache_file)
{
    if (!file_exists($cache_file)) {
        $file = fopen($cache_file, "w");
        //changed r to w
        fclose($file);
    }
    if (time() - filemtime($cache_file) >= 90) {
        require "twitter.lib.php";
        require "config.php";
        $twitter = new Twitter($twitteruser, $twitterpass);
        $xml = $twitter->getMentions();
        $twitter_status = new SimpleXMLElement($xml);
        $fp = fopen($cache_file, 'w');
        //changed twitter.csv to $cache_file
        foreach ($twitter_status->status as $status) {
            foreach ($status->user as $user) {
                fputcsv($fp, array($status->created_at, $status->id, $status->text, $status->source, $user->name, $user->screen_name, $user->description, $user->profile_image_url, 'http://www.twitter.com/' . $user->name, $user->followers_count));
            }
        }
        fclose($fp);
    }
}
Ejemplo n.º 2
0
<?php

require_once 'config.php';
require_once 'functions.php';
require_once 'Twitter.php';
$twitter = new Twitter();
$twitter->setCredentials($config['username'], $config['password']);
$next_tweet = file_get_contents(dirname(__FILE__) . '/nextCoffeeTweet.txt');
$since_id = file_get_contents(dirname(__FILE__) . '/lastMention.txt');
$mentions = $twitter->getMentions($since_id);
if (!is_array($mentions)) {
    die;
}
foreach ($mentions as $mention) {
    if ((string) $mention->id > $since_id) {
        $since_id = (string) $mention->id;
    }
    if (strpos(strtolower($mention->text), 'wann') !== false || strpos(strtolower($mention->text), 'when') !== false) {
        $time = $next_tweet - time();
        if ($time <= 0) {
            $next_tweet = calculateNextCoffeeTweet();
            $time = $next_tweet - time();
        }
        if (date('w', $next_tweet) == 0 || date('w', $next_tweet) == 6) {
            $message = 'erst wieder am Montag';
        } else {
            if (date('d', $next_tweet) != date('d')) {
                if (date('w', $next_tweet) == 1 && date('w') == 5) {
                    $message = 'am Montag';
                } else {
                    if ($next_tweet - time() < 24 * 3600) {