17/10/2017 11:01am
Nice open-call #reserch #fellowships programmes at LMU Munich [LINK]
16/10/2017 3:09pm
#robots that can merge and split their collective architecture (but the article title is preposterous @IEEESpectrum) [LINK]
13/10/2017 1:46pm
RT @MMGiuliani: First demo of our new human-robot interaction setup. Come visit us at @BristolRobotLab to have a look 😀. [LINK]
12/10/2017 12:18pm
Interesting possible projects at Amazon: among others, a network of drone maintenance and delivery systems [LINK] @Verge
10/10/2017 9:41pm
RT @Robohub: 25 women in robotics you need to know about – 2017 [LINK] [LINK]

[How I Added My Twitter Feed]

Added on 18/08/2012
Tags: web

Following my decision to leave Facebook, I have decided to start using Twitter more as a means of exchanging information with my friends. Adding a Twitter feed is pretty easy as Twitter does not require you to authenticate so you can just ask for N latest tweets using an ordinary GET request.

I modified original PHP code posted on Stack Overflow to create a single function that gets the feed and converts it to tweet objects containing createdDate and message fields. Also, I added my own algorithm that automatically creates html links when it finds phrases starting with http:// . Finally, I used a method by kn00tcn to convert Twitter date to PHP date object and back to a string with my own formatting.

The PHP function is as follows:

* Get tweets

protected function getTweets() {
   //-- curl request    
   $url = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=elendurwen&count=5&trim_user=true";
   $ch = curl_init();    $timeout = 5;
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   $json = curl_exec($ch);

   //-- parse data:
   $tweets = array();
   if ($json != false) {
      $obj = json_decode($json);

      foreach($obj as $var => $value) {
         //-- convert the date and add 4 hours to it. For some reason the conversion makes the date 4 hours less than it should be.

         $tweet['createdDate'] = date("d/m/Y g:ia",strtotime($obj[$var]->created_at) + 4*60*60);
         //-- get the message text
         $tweet['message'] = $obj[$var]->text;
         //-- add links automatically
         $tweet['message'] = preg_replace('/(?<!a href=\")(?<!src=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i', '\\0', $tweet['message']);
         //-- replace twitter name tags with links
         $tweet['message'] = preg_replace('/(?<=^|\s)@([a-z0-9_]+)/i','@$1', $tweet['message']);
         //-- replace twitter hash tags with links
         $tweet['message'] = preg_replace('/(?<=^|\s)#([a-z0-9_]+)/i','#$1', $tweet['message']);
         $tweets[] = $tweet;
   return $tweets;

{Please enable JavaScript in order to post comments}


Robot swarms in action

Watch e-puck robots collect resources and bring them back to base. While the previous simulation work helped us to learn a lot about the...

[read full]

How to compile code for e-puck robots on your computer

Compiling code natively on e-puck robots or cross-compiling on your computer can be very tedious. Luckily, there is a third option:...

[read full]

Coding for tomorrow: Why is good code important?

"Why should I care about how my code is written, as long as it works?" I will argue here that well-structured and well-written code not...

[read full]

How Coding in Python Might Be Bad For You

7 reasons why coding in Python is like writing a really bad essay and getting away with it

[read full]