0

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.

Community
  • 1
  • 1

2 Answers2

1

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.

marlen
  • 473
  • 6
  • 20
  • Thanks, Marlen. It is only allowed to query for 500 entries at a time, I assumed that all my projects were in the first page, while doing https://www.transifex.com/api/2/projects/?start=501&end=1000 and then https://www.transifex.com/api/2/projects/?start=1001&end=1500 and so on, doing so I can GET all my projects. – Al Moretti Jun 20 '14 at 15:08
0

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.

marlen
  • 473
  • 6
  • 20
  • Thanks for your answer, Marlen. I'm aware of that API request, and works fine with the code I gave (and with requests too), it returns "all the projects I have access to" (about 200 projects, mostly non-private projects and test projects), but strangely enough, just five or six of those are from my organization. But if I click on any project listed in my homepage, all of them coming from my organization, I can work on any of them, so I have access to all of them, but they are not returned with the API call. I tried requests with the home page, with no results, I always get the login page. – Al Moretti Jun 05 '14 at 07:33