I'm looking to retrieve the followers on some account with more than 5000 followers.
I've seen in a other topic than it's easier to proceed by page then by items per page. (link : tweepy count limited to 200?)
Once it reads all the id, it must check on the profile description if there is a element of a list i created before.
here's my previous code (note op, without using the api.followers):
for element in liste2:
print element
resultats = api.search_users(q=element, count=5000)
for user in resultats:
print user.id
i = 0;
user = api.get_user(user.id)
print user.name
while (i != 4):
if (user.description.find(liste1[i])!= 1):
print user.name + " valide"
i = 4;
statuses = api.user_timeline(id = user.id, count = 20\
0)
The counter doesn't work that's why i want to switch for api.followers witch seems to be more nice.
Thanks for reading
Related
I want to search the whole timeline of a specific user for a particular query
I tried setting the .items() to the total number of tweets in the user profile
but I'm not getting any results back .. any idea on how to solve this issue?
username="No_Rumors"
t =" from:No_Rumors"
z= "أمين رابطة العالم الإسلامي يقرع جرس الكنيسة النصرانية"
no_of_tweets = api.get_user(screen_name=username).statuses_count
query=z+t
t = tweepy.Cursor(api.search,q=query).items(no_of_tweets)
for tweet in t:
print(tweet.text)
I am using two slack API's, users.list() and users.getPresence(). I use users.list() to retrieve the user's names and IDs.
The users.getPresence() API takes the user ID as a parameter and only outputs their presence of 'active' or 'away' as it is shown here: https://api.slack.com/methods/users.getPresence
I tried taking the names I retrieved from users_list() and returning them along with the users_getPresence() API, but then I only got the list of names to repeat over each status.
client = slack.WebClient(API_KEY)
def users_list():
users_call = client.users_list()
users = users_call['members']
result = []
# loops for each user
for user in users:
uid = user['id']
name = user['profile']['real_name']
info = {"id": None, "name": None}
if users_call['ok']:
info['id'] = uid
info['name'] = name
result.append(info)
else:
return None
return result
def users_getPresence():
info = users_list()
users = []
for value in info:
uid = value['id']
users.append(uid)
presence = []
for user in users:
presence_call = client.users_getPresence(user = user)
if presence_call['ok']:
presence.append(presence_call['presence'])
else:
return None
return presence
Right now, the two API's have separate outputs, where users.list() returns ID and name while users.getPresence() returns presence.
How can I return the user's name and their status together?
Here is an updated version of your 2nd function that returns the list of all users with their presence status. Notice that I also added a sleep so you do not violate the rate limit of max 50 calls per minute.
def users_getPresence():
users = users_list()
for user in users:
presence_call = client.users_getPresence(user = user['id'])
sleep(1.2)
if presence_call['ok']:
user['presence'] = presence_call['presence']
else:
user['presence'] = None
return users
I also saw a couple of issues with your first function. Mainly checking for ok in the loop does not work, because if the method fails it will not contain any users and your script will fail before it reached the ok check.
Use this is code snippet :
user = api.get_user('xxxx')
print(user.followers_count)
for i in user.friends():
print(i.screen_name)
result for follower count is 700
but why when looping all data only show 21 row data?
Whilst getting the names of all followers of a user is possible you are likely to get banned from exceeding rate limits quickly.
The following code will tell you how many followers a user has and then list all the username of the people who follow the user.
username = 'keely_bro'
userID = api.get_user(username)
print('User is followed by ' + str(userID.followers_count) + ' people')
print('usernames of followers: ')
for allFollowers in tweepy.Cursor(api.followers_ids, screen_name=username).pages():
followerNames = [userID.screen_name for userID in api.lookup_users(allFollowers)]
for follow in followerNames:
print(follow)
I am usign Flask-SQLAlchemy’s paginate(). Now I need to find what is the page for a specific comment id.
For example, this will work, if I have all comments in the same page:
new_dict['url'] = '/comments#comment_' + str(comment.id)
However in my case I need this structure:
/comments?page=1#comment_73
How can I find what is the page?
From the docs, the Pagination class has .items and .has_next properties and a .next method we can use:
page_number = 0
search = Comment.query.get(15)
query = Comment.query.filter(Comment.id<40)
for num in range(1, query.paginate(1).pages + 1):
if search in query.paginate(num).items:
page_number = num
break
or
page_number = 0
search = Comment.query.get(15)
pag = Comment.query.filter(Comment.id<40).paginate(1)
while pag.has_next:
if search in pag.items:
page_number = num
break
pag.next()
As far as I know, Celeo's answer won't work. For example, what pag.next() does in his code, based on documentations is:
Returns a Pagination object for the next page.
So, basically, it's doing nothing unless you update your variable; and I recommend you to not create a new query since you already have the comment_id so:
comment_id=request.args.get('comment_id')
if comment_id and comment_id.isdigit():
comment_id = int(comment_id )
page_number = -1
index = 1 # page numbers are 1 indexed in Pagination Object
while comments_pagination_object.has_next:
for comment in comments_pagination_object.items:
if comment.id == comment_id :
page_number = index
break
if page_number != -1:
break
index += 1
product_items = product_items.next()
Then, in the URL, you will have something like:
/comments?comment_id=2
and the part product_items.next() is changing the PaginationObject's page till one of it's items (which in this case is a type of class Comment) has the same id as your request args.
I need to send mail to particular user from the database. i have data table where 1000 of records are available. each record have some email ids. or some id has assigned to multiple record . i need to send record to the particular email only.
I have form from where i used to select company name and strt date. from these i fetch all the value into list. now worries is how to send record to particular user
let my code example
def sendmail():
form = SQLFORM.factory(Field('select_company', db.company, represent=lambda c, row:get_company_name(c), requires = IS_IN_DB(db,'company.id','%(company)s')),
Field('choose_start_date','date',requires=IS_NOT_EMPTY(error_message='Please choose Start Date')),
Field('choose_end_date','date',requires=IS_NOT_EMPTY(error_message='Please choose end Date')))
if form.accepts(request,session):
session.company = form.vars.select_company
session.strtdate = form.vars.choose_start_date
session.enddate = form.vars.choose_end_date
mailidr()
return dict(form=form)
def mailidr():
from gluon.tools import Mail,datetime
mail=Mail()
#specify server
mail=auth.settings.mailer
mail.settings.server='smtp.gmail.com:587'
mail.settings.login='comdummy09#gmail.com:critical#009'
#specify address to send as
mail.settings.sender='comdummy09#gmail.com'
#send the message
list = []
for row in db((db.tracker.company == session.company) & (db.tracker.Complience_Status != 1) & (db.tracker.periodicity_due_date >= session.strtdate) & (db.tracker.periodicity_due_date <= session.enddate)).select():
list.append('<tr><td style="padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;">'+row.Compliance_Area+'</td><td style="padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;">'+row.law_description+'</td><td style="padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;" >'''+row.activity_name+'''</td><td style="padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;">'+str(row.periodicity_due_date)+'</td></tr>')
mail.send(to=[row.client_owner],
subject='Compliance and Due_Date',
message='<html>'
'<body>'
'<h1>Test Mails</h1>'
'<h2>Dear \t' +session.company+ '</h2>'
'</br><h3>REMINDER</h3>'
'<p>Please note that the fol1ing records are due between ' +session.strtdate+ ' to ' +session.enddate+ '</p>'
'<table border=1>'
'<thead >'
'<tr>'
'<th style="padding-top:5px;padding-bottom:5px;padding-right:5px;padding-left:5px;">Compliance Area</th>'
'<th>record</th><th>date (Due Date)</th>'
'</tr>'
'</thead>'
'<tbody>'
+str(list)+
'</tbody>'
'</table>'
'</body>'
'</html>')
response.flash='mail send'
return ''
from this code i a able to send mail. but problem is that user get n no mails
if i used to take mail.send to out side the function its not work
from the docs (http://www.web2py.com/books/default/chapter/29/08/emails-and-sms#Setting-up-email)
Mail returns True if it succeeds in sending the email and False
otherwise. A complete argument list for mail.send() is as follows:
So, for a test you should try capturing the response - e.g. change:
mail.send(to=[row.client_owner],
to
mail_response = mail.send(to=[row.client_owner],
and then return locals() instead of "" so you can see in a test page what (if any) failure you are getting in the send. this is just for testing...
A permanent alternate method is shows here: i am trying send email using web2py with gmail and using smtp setting i have attached all code