get holder of solana nft using python - python

I want to get the current holder (and also all past holders list) of a specific Solana NFT, using python.
Currently, I'm using get_confirmed_signature_for_address2 to get the token signatures, then I get the transaction of the newest signature, and then I extract the owner using: transaction["result"]["meta"]["postTokenBalances"][0]["owner"]
But it seems like a really long way to get the holder and I wonder if there is a better way to get it.

I found the solution at: https://solanacookbook.com/references/nfts.html#get-the-owner-of-an-nft
First, need to get the largest token account, it can retrieve using getTokenLargestAccounts.
Then need to take it and parse it using getParsedAccountInfo, it'll give the owner address from the associate address.
The code is in TS, but the same logic goes in python.

Related

Repeat a Python Function - execute the same number of times as entries in a list

Recently I found a python module for one of our COTS products (Tenable) here at the office. It was developed to help access the product's API. I have it installed in my lab here alongside Python 3.9.10 and based on my observations it is working ok. No problems executing simple code.
This product hosts file repositories that manage uploads from thousands of users. The Python module contains a specific function for making edits to those repositories. That function is very specific about the type of Python object that can be specified. For example, the id number has to be an integer. The name has to be a string, and the allowed IPs have to be a list, etc.
The exact challenge I am facing here is that I need to perform edits on 12 repositories. The data is stored in an external JSON file that I access via json.load.
I can successfully perform an edit (using information in the JSON) on a single repository.
This is how I did it:
x = sc.repositories.edit(repository_id=(repo_id[-1]), name=repo_name[-1], allowed_ips=(ip_list[-1]))
sc.repositories.edit is defined in the module. repo_id, repo_name, and allowed_ips are lists of data that come from the JSON. I then used the position [-1] to tell Python to plug in the last entries in the list. The API considers this a PATCH
This seems to work as expected. I can log into the web application and see the changes.
...but is there a way to repeat this function until it has sent the updates for all 12 repositories?
I can successfully send this using a [0], [-1], or other position. But the module won't accept slices and I don't know how to loop something this complicated.
Thanks in advance.
If I understood you correctly, you could use zip, or even just a simple range-based for-loop:
for current_repo_id, current_repo_name, current_ips in zip(repo_id, repo_name, ip_list):
x = sc.repositories.edit(
repository_id=current_repo_id,
name=current_repo_name,
allowed_ips=current_ips
)

Python use API to get data

I am kind of stucked in trying to solve following issue: I try to access a web-page in order to get some data for a supplier (need to do it for work) in an automated way, using an api
The API is called https://wl-api.mf.gov.pl and shall provide information stored in json for supplier which can be found over their tax ID.
I use the request package and I am able to manage to get positive response:
import requests
nip=7393033097
response=requests.get("https://wl-api.mf.gov.pl")
print(response) --> Response [200]
If I click on the link and scroll until I find the specific part for the tax information, I find the following line
GET /api/search/nip/{nip}
So what I did is to add this line into my response variable, since this is how I understood it - and there is the point where I think I am wrong
response=requests.get("https://wl-api.mf.gov.pl/search/7393033097/{7393033097}")
However, I cannot access it.
Am I doing something wrong - I do believe yes - and can anyone give me a little help :)
Update: If I check the requirements / documentation I find following information where I need a bit support to implement it
GET /api/search/nip/{nip}
(nip?date)
Single entity search by nip
**Path parameters**
nip (required)
*Path Parameter — Nip*
**Query parameters**
date (required)
*Query Parameter — format: date*
**Return type**
EntityResponse
Example data
Content-Type: application/json
I think this line:https://wl-api.mf.gov.pl/search/7393033097/{7393033097} should be like this:
https://wl-api.mf.gov.pl/search/nip/7393033097

Filter list of clients in paymill (preferably using the python pymill library)

Getting a list of clients from paymill using pymill works (almost) fine:
p = pymill.Pymill(private_key)
clients = p.get_clients
Yet the result only contains 20 entries and not the entry with a specific email address that I am willing to retrieve. When using the export_clients API method, all clients are returned as CSV including the client which I seek. The documentation[1] says that there is a possibility to sort and filter clients, yet it seems that pymill cannot do this. So I guess I will have to extend pymill to generate the correct REST requests? An alternative would be to parse the CSV client side, but this will not scale.
[1] https://www.paymill.com/en-gb/documentation-3/reference/api-reference/#sorting
Why don't you increase the entries? This is made via count attribute. e.g: curl https://api.paymill.com/v2/clients?count=1000. Than you needn't download the csv.
Best,
Christian
You don't need to scan the CVS list to filter by email. Just use the filter option. It works like this:
GET https://api.paymill.com/v2/clients?email=urlencodedemail
Unfortunately the python wrapper does not support list filters and orders, but you are welcome to make a contribution. It's an open source project, i am sure they will accept a nice pull request :)

Is this possible to write a program to inter-act with existing software?

For example, if the program did not provide an API, and I need it to do something from Python script, is this possible to do so? Let's give an example:
I would like to copy the Product ID from the Internet Explorer's product ID everyday and new a text file named in this format: ddmmyyyy, and store on desktop. It is stupid, so, I would like to handle it to the machine to do it. (Yes, it is useless, but just say, it is an example.)
Creating a text file, with a string is easy to implement, but the REAL question is, how can I get the product ID from the program that don't have API provided.
So, the IE didn't provide the API for developer to access the Product ID, and I think the value can be shown on the screen or registry. Assume that I don't know the register location or they simply didn't store it in the registry, what I can get this product ID is manually, click, and check. For this process, is this possible to make it automatic? Thanks.
If the Info ur looking for is showed by IE you can obtain it by using xpath. If you want to make it automatic you could use selenium which works with webs as well.
If the program doesnt provide an api then its not possible to interact with the program unless you get the output from a browser or you may use programs like Sikuli and obtain the info for example by image processing

How can I edit a secondary calendar using google python API

I wonder if it's possible to create and delete events with Google API in a secondary calendar. I know well how to do it in main calendar so I only ask, how to change calendar_service to read and write to other calendar.
I've tried loging with secondary calendar email, but that's not possible with BadAuthentication Error. The URL was surely correct, becouse it was read by API.
Waiting for your help.
A'm answering my own question so I can finally accept this one. The problem has been solved some time ago.
The most important answer is in this documentation.
Each query can be run with uri as argument. For example "InsertEvent(event, uri)". Uri can be set manually (from google calendar settings) or automatically, as written in post below. Note, that CalendarEventQuery takes only username, not the whole url.
The construction of both goes this way:
user = "abcd1234#group.calendar.google.com"
uri = "http://www.google.com/calendar/feeds/{{ user }}/private/full-noattendees"
What's useful, is that you can run queries with different uri and add/delete events to many different calendars in one script.
Hope someone finds it helpful.
I got the same issue but I found this solution (I do not remember where)
This solution is to extract the secondary calendar user from its src url provided by google
This is probably not the better one but it's a working one
Note:the code is extracted from a real project [some part has been removed] and must be adapted to your particular case and is provide as sample just to have a support for explaination (It will not work as is)
# 1 - Connect using the main user email address in a classical way
cal_client = gdata.calendar.service.CalendarService()
# insert here after connection stuff
# 2 - For each existing calendars
feed = cal_client.GetAllCalendarsFeed():
# a loop the find the calendar by it's title (cal_title)
for a_calendar in feed.entry:
if cal_title in a_calendar.title.text:
cal_user = a_calendar.content.src.split('/')[5].replace('%40','#')
# If you print a_calendar.content.src.split you will see that the url
# contains an email like definition. This is the one to used to work
# with the calendar
Then you just have to replace the default user by the cal_user in the api to work on the secondary calendar.
Replace call is required because google api function are doing internal conversion on special characters like '%'
I hope this will help you.

Categories

Resources