Skip to content

Instantly share code, notes, and snippets.

@nadia2012
Created March 26, 2012 02:01
Show Gist options
  • Save nadia2012/2202270 to your computer and use it in GitHub Desktop.
Save nadia2012/2202270 to your computer and use it in GitHub Desktop.
twitter project
#done by :nadia alotaibi,wojood alajmi,sara alkahaldy,marow adel
#pip install tweepy
import tweepy
from tweepy.error import TweepError
import json
api = tweepy.API(auth)
##retreave 100 tweets
tweets = tweepy.api.user_timeline("mis350")
x = page
while t in tweets :
if x <=5:
tweet = getUserTimeline("mis350",page=x)
API.create_list(tweet,public)
print tweet.text
# another way
for me in tweepy.cursor(api.me ,id= "mis350" ).items(100):
print me.screen_name
# another way
my_tweets = api.GetUserTimeline(screen_name="mis350",count=100)
print my_tweets
##Show all the mentions in the user timeline with a count of how many times each one occurred.
def show_mentions ():
text =("@mis350")
ment = text.split()
count = {}
for m in ment:
count[m] = count.get(m,0)+1
ruturn
#another way
my_mentions = api.mentions("@mis350",conunt ={})
print my_mentions
##•Show all the hashtags in the user timeline with a count of how many times each one occurred.
def my_hashtag ():
for t in tweets :
s = 'this_is_a_twitter_hashtag_#';
s = s.find('#')
print s
#another way
# php source code
<?php
global $total, $hashtag;
//$hashtag = '#supportvisitbogor2011';
$hashtag = '#australialovesjustin';
$total = 0;
function getTweets($hash_tag, $page) {
global $total, $hashtag;
$url = 'http://search.twitter.com/search.json?q='.urlencode($hash_tag).'&';
$url .= 'page='.$page;
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$json = curl_exec ($ch);
curl_close ($ch);
//echo "<pre>";
//$json_decode = json_decode($json);
//print_r($json_decode->results);
$json_decode = json_decode($json);
$total += count($json_decode->results);
if($json_decode->next_page){
$temp = explode("&",$json_decode->next_page);
$p = explode("=",$temp[0]);
getTweets($hashtag,$p[1]);
}
}
getTweets($hashtag,1);
echo $total;
?>
##•User can select the list of hashtags/mentions and all tweets containing the hashtags/mentions are shown.
streaming_api = tweepy.streaming.Stream(auth, CustomStreamListener(), timeout=60
# Optionally filter the statuses you want to track by providing a list
print >> sys.stderr, 'Filtering the user timeline for "%s"' % (' '.join(sys.argv[1:]),)
streaming_api.filter(show ="@mis350",show ="#mis350")
##Proper error handling and input validation.
x= raw_input("Welcome to tweepy \n its twitter accounts searcher\n Which account you are looking for?\n ")
if x=="350":
print "Welcome to ",x, " twitter account"
else:
print "Sorry ! , invalid inputs , Plaese try again ! "
#Optional
consumer_key=""
consumer_secret=""
# The access tokens can be found on your applications's Details
# page located at https://dev.twitter.com/apps (located
# under "Your access token")
access_token=""
access_token_secret=""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# If the authentication was successful, you should
# see the name of the account print out
print api.me().name
# If the application settings are set for "Read and Write" then
# this line should tweet out the message to your account's
# timeline. The "Read and Write" setting is on https://dev.twitter.com/apps
api.update_status('Updating using OAuth authentication via Tweepy!')
#dirict message
text= raw_input ("compose a new message")
r_messages=API.sent_direct_messages("mis350",count= 2)
print r_messages
s_messages=API.send_direct_message("mis350",text=)
print s_messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment