Created
April 7, 2012 16:44
-
-
Save nadia2012/2330272 to your computer and use it in GitHub Desktop.
mini project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# done by nadia alotaibi 208115517, wjood alajmi 208217252, marwa adel 208115357, sara alkaldy 206216912 | |
import tweepy | |
import sys | |
from tweepy.error import TweepError | |
#retrave 100 tweet | |
while 1: | |
x=raw_input("for Q1 ENTER (tweets) for Q2 ENTER (mentions) for Q3 ENTER(hashtags) and to exit ENTER (quit),please: ") | |
if x=="tweets": | |
user_name = raw_input ("enter a user name: ") | |
print "HELLO" ,user_name | |
tweets =tweepy.api.user_timeline (user_name ,count =100) | |
for t in tweets : | |
print t.text, "\n" | |
elif x== "quit": | |
print "bye bye" | |
quit() | |
else : | |
print "reed the note carfully" | |
## example to a count that works | |
n=0 | |
for s in tweets: | |
m=s.text | |
num=m.count("#") | |
words=m.split ("[") | |
for current_word in words: | |
n=n+1 | |
print (""),n,num | |
print (current_word) | |
##tell here the program works corectly the rest is the hole program and what we hoped for it to look like. | |
while 1: | |
x=raw_input("for Q1 ENTER (tweets) for Q2 ENTER (mentions) for Q3 ENTER(hashtags) and to exit ENTER (quit),please: ") | |
if x=="tweets": | |
user_name = raw_input ("enter a user name: ") | |
print "HELLO" ,user_name | |
tweets =tweepy.api.user_timeline (user_name ,count =100) | |
for t in tweets : | |
print t.text, "\n" | |
elif x=="mentions": | |
print "enter : showMentions (tweets) ,pleas" | |
onsumer_key="" | |
consumer_secret="" | |
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) | |
def showMentions (tweets): | |
# mentions = api.mentions(since_id, max_id, count, page dedent )we didnt know what parameter to put. | |
mention = "@" | |
for t in tweets: | |
if mention in tweets: | |
mentions = api.mentions() | |
count ={} | |
for m in mentions : | |
count [m] = count.get(m,o)+1 | |
print m.text | |
# another try reblace the code under the function with this code : | |
#mentions = api.mentions() | |
#for mention in mentions: | |
#print mention.text | |
#mentionsCount = len(mentions) - 1 | |
elif x == "hashtags" | |
print "enter showHashtags ()" | |
def showHashtags (): | |
f =open('hashtaggers.txt') | |
f2=open('hashtaggersIDs.txt','w') | |
f3=open('hashtaggersIDnName.txt','w') | |
for uid in f: | |
user=api.get_user(uid) | |
f2.write(str(user.id)+'\n') | |
f3.write(uid+','+str(user.id)+'\n') | |
f.close() | |
f2.close() | |
f3.close() | |
#anthor try : | |
#hashtag = "#" | |
#for t in tweets: | |
# if hashtag in tweets: | |
#hashtags = hashtags.find (hashtag) | |
#count ={} | |
#for h in hashtags : | |
#count [h] = count.get(h,o)+1 | |
#print h.text | |
elif x== "quit": | |
print "bye bye" | |
quit() | |
else : | |
print "reed the note carfully" | |
try: | |
user_name =int(raw_input(" enter a user name: " )) | |
break | |
except unicode Error: | |
print "unable to accept arabic characters,try again.." | |
except : | |
print " no valid user name ,try again" | |
except tweepy.TweepError: | |
print 'Error! Failed to get request token.' | |
else: | |
print "x is ", x | |
#optinal | |
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