python-twitter retrieving all followers - python

I'm using the python-twitter library and while I can get the code to retrieve a 'set' of results, apparently in the first 'page' ... I for the life of me can't find the right code to get a set of ALL the followers for a specific account/handle.
I'm using this snip...
target = sys.argv[1]
#returns a twitter.User instance for each follower
users = api.GetFollowers(target)
print [u.screen_name for u in users]
I'd appreciate any pointers, if someone's figured this out already?
Thanks in advance.
/Raf

According to this patch, I guess it has been fixed. Check this sample code.

Related

api.get_user with Tweepy will not give description

I'm trying to use Tweepy (version 4.4.0) to get a user's description but it's seemingly not working:
u = api.get_user(username='XXXX', user_fields=['description'])
but the output of this is simply:
Response(data=<User id=123 name=XXX username=XXX>, includes={}, errors=[], meta={})
So it's getting me the name and id fine, but it's returning an empty for any user fields.
Note I've also tried with user_auth: 1, but I get 'Unauthorized: 401' - but from what I've seen around, I don't think user authentication is the problem here... but maybe it is?
Any advice would be great!
api seems to be an instance of tweepy.Client here.
From the relevant FAQ section in Tweepy's documentation:
Why am I not getting expansions or fields data with API v2 using Client?
If you are simply printing the objects and looking at that output, the string representations of API v2 models/objects only include the default attributes that are guaranteed to exist.
The objects themselves still include the relevant data, which you can access as attributes or by key, like a dictionary.
The user object being returned in the response should have a description field with the user's description.
You can access the description with: u.data.description
Keep in mind that the description may be blank some times, try with created_at to be sure it works.
Sample code for extracting description of any twitter user is as follows
import tweepy
auth = tweepy.OAuth2BearerHandler(os.environ.get("TWITTER_API_KEY"))
api = tweepy.API(auth)
user = api.get_user(screen_name="TechWiser", include_entities=False)
description = user._json['description']
user._json contain many other key, value pair that you can explore

Unable to access jira worklogs via python-jira

I am trying to access the worklogs in python by using the jira python library. I am doing the following:
issues = jira.search_issues("key=MYTICKET-1")
print(issues[0].fields.worklogs)
issue = jira.search_issues("MYTICKET-1")
print(issue.fields.worklogs)
as described in the documentation, chapter 2.1.4. However, I get the following error (for both cases):
AttributeError: type object 'PropertyHolder' has no attribute 'worklogs'
Is there something I am doing wrong? Is the documentation outdated? How to access worklogs (or other fields, like comments etc)? And what is a PropertyHolder? How to access it (its not described in the documentation!)?
This is because it seems jira.JIRA.search_issues doesn't fetch all "builtin" fields, like worklog, by default (although documentation only uses vague term "fields - [...] Default is to include all fields"
- "all" out of what?).
You either have to use jira.JIRA.issue:
client = jira.JIRA(...)
issue = client.issue("MYTICKET-1")
or explicitly list fields which you want to fetch in jira.JIRA.search_issues:
client = jira.JIRA(...)
issue = client.search_issues("key=MYTICKET-1", fields=[..., 'worklog'])[0]
Also be aware that this way you will get at most 20 worklog items attached to your JIRA issue instance. If you need all of them you should use jira.JIRA.worklogs:
client = jira.JIRA(...)
issue = client.issue("MYTICKET-1")
worklog = issue.fields.worklog
all_worklogs = client.worklogs(issue) if worklog.total > 20 else worklog.worklogs
This question here is similar to yours and someone has posted a work around.
There is a also a similar question on Github in relation to attachments (not worklogs). The last answer in the comments has workaround that might assist.

Redmine API to fetch all issue in python

I am trying to fetch all the issue from redmine
list_1 = []
issuess = conn_red.issue.all()
for i in issuess:
list_1.append(i)
print len(list_1)
The print statement result is 575
But In Redmine, I have 2735 issue.
I wonder,
why it is restricting to 575.
Its there any limitation in number of count
Any other possible way to fetch all record
By default, the REST API only returns open issues. If you want to get all issues, you have to define a filter:
issues = conn_red.issue.filter(status_id='*')
Please refer to the documentation of python-redmine as well as the API documentation of Redmine itself.

How do I generate a list of people I follow using Twython?

To get a list of who follows me, I know that I can use:
twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
followers = twitter.get_followers_ids(screen_name = "my_username")
but how do I get a list of who I follow?
While writing this question I was flicking between bits of code trying to work out how to do this, and the answer was painfully simple.
I thought I'd still post this question and answer it myself to perhaps save people some time if they happened to have the same question.
In the line:
followers = twitter.get_followers_ids(screen_name = "my_username")
Just change 'followers' to 'friends', like so:
followers = twitter.get_friends_ids(screen_name = "my_username")
The only confusion in getting to this solution was that I didn't know that on Twitter 'friends of [user]' is actually 'people who [user] follows'.

tweepy get_user does not work with a list of user_ids

I am using tweepy library to pull informations about Twitter users. What I want is, given a list of Twitter ids, get the number of followers of each user that relates to the ids. The function looks like this.
infos = api.get_user(user_id=xxx)
return infos.followers_count
In the Twitter documentation, it says I can input a list of up to 100 user ids to get_user. Thing is, whatever I pass to that function other than a single id, I get the error
[{'message': 'Sorry, that page does not exist', 'code': 34}]
For example if I write:
infos = api.get_user(user_id=[user1,user2,user3])
I get the error. But if I write
infos = api.get_user(user_id=user1)
It works perfectly well. Did you encounter this problem before? Is the problem in Tweepy library? Should I use another library?
Thanks for your support
You need to use the function lookup_users for this, and the parameter is user_ids:
infos = api.lookup_users(user_ids=[user1,user2,user3])
https://github.com/tweepy/tweepy/blob/master/tweepy/api.py#L154

Categories