Launch XNAT pipelina via REST - python

I'm trying to write a script that would be able to launch the pipelines that are added to a specific project (i.e. the script would replace the user clicking on "build" for every subject on a specific project).
In my head I am dividing the problem into three tasks:
Getting the lists of subjects in PROJECT.
Getting the list of pipelines already added in PROJECT.
Launch the selected pipeline (which has to be present in the list generated in 2) for every subject (list collected in 1).
Now, as I see it, I'm already facing some problems:
How could I get a list of subjects for a PROJECT? Maybe using pyXNAT is easier...
How can I retrieve the list of pipelines added in a project?
How can I launch ONE pipeline on ONE subject (the same as clicking build on MR report page) via the REST-API? Is it possible?
I'm using XNAT 1.6.3
with Tomcat 6.0.41
and PostgreSQL 9.1
on Ubuntu 14.04
I hope my question is clear and thanks for your time!!

I have no answers regarding the pipelines, although I figure they can be triggered via REST protocol. For the basic stuff, have a look at the pyxnat documentation https://pythonhosted.org/pyxnat/index.html#short-examples

Related

How to get a list of Folders and Files in Sharepoint

I have started to explore the Graph API, but Sharepoint is quite complicated and I am not sure how to proceed. I previously have worked with OneNote using this API successfully.
Purpose: There are thousands of folders/files and I need to go through the list in order to organize it in a better way. I am looking for a way to export this list into Excel/CSV using Python and Graph API
I want to dynamically get a list of all underlying Folders and files visible from this URL:
https://company1.sharepoint.com/teams/TEAM1/Shared Documents/Forms/AllItems.aspx?id=/teams/TEAMS_BI_BI-AVS/Shared Documents/Team Channel1/Folder_Name1&viewid=6fa603f8-82e2-477c-af68-8b3985cfa525
When I open this URL, I see that this folder is part of a private group called PRIVATE_GROUP1 (on the top left).
Looking at some sample API calls here:
GET /drives/{drive-id}/items/{item-id}/children -> Not sure what drive-id
GET /groups/{group-id}/drive/items/{item-id}/children -> I assume group-id refers to private group. Not sure how to get the ID
GET /sites/{site-id}/drive/items/{item-id}/children -> Assuming site-id is 'company1.sharepoint.com'?
For all above not sure what item-id refers to...
Thanks
refer below code. This might help you.
https://gist.github.com/keathmilligan/590a981cc629a8ea9b7c3bb64bfcb417

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
)

Download latest version from Github, unzip to folder and overwrite contents?

I have a Node project that's bundled and added to Github as releases. At the moment, it checks my Github for a new release via the API and lets the user download it. The user must then stop the Node server, unzip the release.zip to the folder and overwrite everything to update the project.
What I'm trying to do is write a Python script that I can execute in Node by spawning a new process. This will then kill the Node server using PM2, and then Python script will then check the Github API, grab the download url, downloads it, unzips the contents to the current folder, deletes the zip and then starts up the Node server again.
What I'm struggling with though is checking the Github API and downloading the latest release file. Can anyone point me in the right direction? I've read that wget shouldn't be used in Python, and instead use urlopen
If you are asking for ways to get data from a web server, the two main libraries are:
Requests
Urllib
Personally, I prefer requests. They both have good documentation.
With requests, getting JSON data is as simple as:
r = requests.get("example.com")
r = r.json()
You can add headers and other information easily, though keep in mind that while it supports HTTP, it doesn't support HTTPS.
You need to map out your workflow and dataflow better. You can do it in words or pictures. If you can express your problem clearly and completely in words step by step in list format in words, then translate it to pseudocode. Python is great because you can go almost immediately from a good written description, to pseudocode, to a working implementation. Then at least you have something that works, and you can optimize performance, simplify functionality or usability from there. This is the process of translating a problem into a solution.
When asking questions on SO, you need to show your current thinking, what you've already tried, preferably with your code that doesn't yet work, or work the way you need it to work. People can vote you down and give you negative reputation points if you ask a question with just a vague description, a question that is an obvious cry for help with homework (yours is not that), or a muse or a vague question with not even an attempt at a solution, because it does not contribute back to the community in any way.
Do you have any code or detailed pseudocode steps for checking the GitHub API and checking for the "latest release" of file(s) you are trying to update?

Get spotify currently playing track

EDIT : Let's try to clarify all this.
I'm writing a python script, and I want it to tell me the song that Spotify is currently playing.
I've tried looking for libraries that could help me but didn't find any that are still maintained and working.
I've also looked through Spotify's web API, but it does not provide any way to get that information.
The only potential solution I found would be to grab the title of my Spotify (desktop app) window. But I didn't manage to do that so far.
So basically, what I'm asking is whether anyone knows :
How to apply the method I'm already trying to use (get the window's title from a program), either in pure python or using an intermediary shell script.
OR
Any other way to extract that information from Spotify's desktop app or web client.
Original post :
I'm fiddling with the idea of a python status bar for a linux environment, nothing fancy, just a script tailored to my own usage. What I'm trying to do right now is to display the currently playing track from spotify (namely, the artist and title).
There does not seem to be anything like that in their official web API. I haven't found any third party library that would do that either. Most libraries I found are either deprecated since spotify released their current API, or they are based on said API which does not do what I want.
I've also read a bunch of similar question in here, most of which had no answers, or a deprecated solution.
I thought about grabbing the window title, since it does diplay the information I need. But not only does that seem really convoluted, I also have difficulties making this happen. I was trying to get it by running a combination of the linux commands xdotools and xprop inside my script.
It's worth mentionning that since I'm already using the psutil lib for other informations, I already have access to spotify's PID.
Any idea how I could do that ?
And in case my method was the only one you can think of, any idea how to actually make it work ?
Your help will be appreciated.
The Spotify client on Linux implements a D-Bus interface called MPRIS - Media Player Remote Interfacing Specification.
http://specifications.freedesktop.org/mpris-spec/latest/index.html
You could access the title (and other metadata) from python like this:
import dbus
session_bus = dbus.SessionBus()
spotify_bus = session_bus.get_object("org.mpris.MediaPlayer2.spotify",
"/org/mpris/MediaPlayer2")
spotify_properties = dbus.Interface(spotify_bus,
"org.freedesktop.DBus.Properties")
metadata = spotify_properties.Get("org.mpris.MediaPlayer2.Player", "Metadata")
# The property Metadata behaves like a python dict
for key, value in metadata.items():
print(key, value)
# To just print the title
print(metadata['xesam:title'])
For windows:
The library can be found at github: https://github.com/XanderMJ/spotilib. Keep in mind that this is still work in progress.
Just copy the file and place it in your Python/Lib directory.
import spotilib
spotilib.artist() #returns the artist of the current playing song
spotilib.song() #returns the song title of the current playing song
spotilib.artist() returns only the first artist. I started working on an other library spotimeta.py to solve this issue. However, this is not working at 100% yet.
import spotimeta
spotimeta.artists() #returns a list of all the collaborating artists of the track
If an error occurs, spotimeta.artists() will return only the first artist (found with spotilib.artist())

Call python script from Jira while creating an issue

Let say I'm creating an issue in Jira and write the summary and the description. Is it possible to call a python script after these are written that sets the value for another field, depending on the values of the summary and the description?
I know how to create an issue and change fields from a python script using the jira-python module. But I have not find a solution for using a python script while editing/creating the issue manually in Jira. Does anyone have an idea of how I manage that?
I solved the problem by using the Add-on Script runner in Jira. There I created a scripted field in Groovy and called the command prompt and run the python script from there. Here is a simple example of the script
def process = ['cmd', '/c', 'filepathToPython.exe', 'filepathToPythonFile.py'].execute()
process.waitfor()
return p.text
process?.err?.text can be used instead of process.text if one want to see eventual error messages.
Take a look at JIRA webhooks calling a small python based web server?

Categories

Resources