Python 3 how to retrieve Transifex dashboard page

176 Views Asked by At

I'm a Transifex user, I need to retrieve my dashboard page with the list of all the projects of my organization. that is, the page I see when I login: https://www.transifex.com/organization/(my_organization_name)/dashboard

I can access Transifex API with this code:

import urllib.request as url

usr = 'myusername'
pwd = 'mypassword'

def GetUrl(Tx_url):
    auth_handler = url.HTTPBasicAuthHandler()
    auth_handler.add_password(realm='Transifex API',
                          uri=Tx_url,
                          user=usr,
                          passwd=pwd)
    opener = url.build_opener(auth_handler)
    url.install_opener(opener)
    f = url.urlopen(Tx_url)
    return f.read().decode("utf-8")

everything is ok, but there's no API call to get all the projects of my organization. the only way is to get that page html, and parse it, but if I use this code, I get the login page.

This works ok with google.com, but I get an error with www.transifex.com or www.transifex.com/organization/(my_organization_name)/dashboard

Python, HTTPS GET with basic authentication

I'm new at Python, I need some code with Python 3 and only standard library.

Thanks for any help.

2

There are 2 best solutions below

1
marlen On BEST ANSWER

The call to

/projects/

returns your projects along with all the public projects that you can have access (like what you said). You can search for the ones that you need by modifying the call to something like:

https://www.transifex.com/api/2/projects/?start=1&end=6

Doing so the number of projects returned will be restricted.

For now maybe it would be more convenient to you, if you don't have many projects, to use this call:

/project/project_slug

and fetch each one separately.

1
marlen On

Transifex comes with an API, and you can use it to fetch all the projects you have.

I think that what you need this GET request on projects. It returns a list of (slug, name, description, source_language_code) for all projects that you have access to in JSON format.

Since you are familiar with python, you could use the requests library to perform the same actions in a much easier and more readable way.

You will just need to do something like that:

import requests
import json

AUTH = ('yourusername', 'yourpassword')
url =  'www.transifex.com/api/2/projects'

headers = {'Content-type': 'application/json'}

response = requests.get(url, headers=headers, auth=AUTH)

I hope I've helped.