Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Convert a Short Python script to PHP
Old 03-16-2009, 06:02 PM Convert a Short Python script to PHP
Junior Talker

Posts: 3
Name: Josh
Trades: 0
Can anyone please convert this short little python script to PHP. I had a go at it myself with no luck

Code:
#!/usr/bin/python
#(c) 2009 Ben McIlwain, released under the terms of the GNU GPL v3.
import twitter
from sets import Set

username = 'username_here'
password = 'password_here'
api = twitter.Api(username=username, password=password)

following = api.GetFriends()
friendNames = Set()
for friend in following:
    friendNames.add(friend.screen_name)

followers = api.GetFollowers()
for follower in followers:
    if (not follower.screen_name in friendNames):
        api.CreateFriendship(follower.screen_name)
Thank You!
wee493 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-16-2009, 06:44 PM Re: Convert a Short Python script to PHP
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You're going to need to find a PHP version of that API. Assuming that there is a drop in replacement for it the code would look like:
PHP Code:
require_once('twitter.php'); //the path to the twitter api .php file

$username 'username_here';
$password 'password_here';
$api = new Api($username$password); //this line may be different
//depending on what the twitter constructor looks like

$following $api->getFriends();
$friendNames = array();
foreach(
$following as $friend)
{
     
$friendNames[] = friend->screen_name;
}

$followers $api->GetFollowers();
foreach(
$followers as $follower)
{
    if(!
in_array($follower->screen_name$friendNames))
    {
          
$api->CreateFriendship($follower->screen_name);
    }

This code might be different depending on differences between the php and python twitter api.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-16-2009, 09:51 PM Re: Convert a Short Python script to PHP
Junior Talker

Posts: 3
Name: Josh
Trades: 0
Thank You soo much! +Rep
wee493 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Convert a Short Python script to PHP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11573 seconds with 12 queries