Get multiple connections at once with Python facebook package - python

To get connections using the Python facebook package I know to use:
g.get_connections("me", "friends")
But is there a way to get "friends" and "books" in one call?
Didn't see anything in the docs...

Based on the Graph API documentation, you can do a request in the form
GET graph.facebook.com
/{node-id}?
fields={first-level}
Thus, you'd want to execute a GET for /me?fields=friends,books, looking at the facebook-sdk code, the g.get_object seems to be the closest one, thus:
g.get_object('/me', fields='friends,books')
Of course chances are that not all are returned, and you need to page through the results anyway...

Related

How to remove my own instagram followers with Python?

I want to remove my own instagram followers without blocking them, using python.
I have seen many, many, many, many instagram python libraries online that allow you to stop or start following a person, but that is not what I'm looking for; I don't want to remove who I am following or start following someone, I want to remove people who are following me.
I looked into the official documentation of Instagram's HTTP API trying to make my own solution, but I couldn't find the documentation of this action under any endpoint ( I assume it should be under /friends/ ).
I vaguely remember some library that used to do this, but I cannot find it. Does anyone know of a good way to achieve this, preferably via passing an inclusion/exclusion list for the followers I want to have as a result?
I found a solution in an old library that does something similar. You can't directly remove followers through most tools, but if you block and then unblock a user, the effect you want is achieved. Example code:
# https://instagram-private-api.readthedocs.io/en/latest/_modules/instagram_private_api/endpoints/friendships.html
import instagramPrivateApi
# ...
# Implement a Client class that inherits FriendshipMixin
api = new Client()
api.friendships_block(uid)
api.friendships_unblock(uid)
Here is the API endPoint for removing a follower https://www.instagram.com/web/friendships/{user_id}/remove_follower/
You can do a post request on this URL with appropriate headers and that can do the job.

Querying Customer Saved Searches in Shopify Python API

I'm trying to get all customers who abandoned their order last week.
I was able to achieved it through the REST API, however, I wonder how to achieve the same thing via Shopify Python API.
Here's the code I tried in Postman:
https://{shop}.myshopify.com/admin/api/2019-07/customer_saved_searches/{customer_saved_search_id}/customers.json?limit=250
Also, it seems like there's a 250 results limit in the REST API, is there a way to exceed it?
The Python SDK is a bit of afterthought of Shopify. Sadly.
Regarding the paging on th REST request. Just add the query parameter ...?page=2 at the end of your URL.
Regarding the Python SDK, following will do the trick:
id = 23423423423
css = shopify.CustomerSavedSearch.find(id)

Python code to connect to twitter search API

I'm new to Python and am very confused on how to begin this assignment:
Write Python code to connect to Twitter search API at:
https://api.twitter.com/1.1/search/tweets.json
with at least the following parameters:
q for a search topic of your interest;
count to 100 for 100 records
to retrieve twitter data and assign the data to a variable.
I already created the app to access Twitter's API. Thanks.
I had this same issue. According to Twitter, you must register an account to even use basic search features of public tweets and there is no way around it. I followed the guide for the complete setup here and can confirm it works
Edit: the article is for php, but changing it to python shouldn’t be very difficult. It has all the methods outlined in the article
Just as a hint, you might want to use tweepy for this. They have very good documentation and its much easier than trying to reinvent the wheel.

Show Server details via Python OpenStack API using the nova client

I am trying to convert my BASH script to Python and am having difficulties in finding the equivalent code for openstack server show or openstack server list --long. I would like to know what host is my server currently located and use this information for a check before migrating it to another host.
Looking through the latest novaclient documentation and its servers module, I have found two potential commands that I was hoping would accomplish the task, but does not do so:
list(detailed=True)
Gets a list servers
detailed=True should return detailed server info (optional).
This returns a regular list of servers with their names.
get(server)
Get a server
This returns only the name of the server.
I have been researching for the past two days, and I could not find the same / similar problem here in stack overflow so I have decided to ask and I am hoping that someone can help me with this.
Either list or get should be fine here.
As an example get would be used like this.
instance = nova_client.servers.get('my-server')
print(instance.name)
print(instance.addresses)
print(instance.status)
Or using list.
for instance in nova_client.servers.list():
print(instance.name)
print(instance.addresses)
print(instance.status)
If you want an easy way of understanding the type of data you can get, you can simply use the Python inbuilt dir.
instance = nova_client.servers.get('my-server')
print(dir(instance))
'my-server' needs to be the id as in instance.id, the name of the server is not valid.
I cant yet comment, so i wrote an answer.

Distinguishing between GET and POST data in CherryPy?

I've been deciding between Python web frameworks for a project of mine and I've really liked how lightweight, flexible, and concise CherryPy is compared to others. The only problem I'm having is I can't find any documentation on how to distinguish between data sent via GET and via POST.
For example, I don't want users to be able to provide their login credentials through a GET request (http://example.com/login?username=user&password=pass) but, according to CherryPy's tutorial, all data is sent as method parameters, no matter what HTTP method they're sent as. Is there some way to say I only want the POST data or do I have to use MethodDispatcher?
Thanks!
See the docs.
A string containing the HTTP method, such as "GET" or "POST". Set
in the "run" phase.
looks like checking cherrypy.request.method is what you want to do.

Categories