Last active
December 19, 2015 18:59
-
-
Save erichnascimento/6002915 to your computer and use it in GitHub Desktop.
Exemplo consumo YouCloud webservice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: latin-1 -*- | |
| import urllib | |
| import urllib2 | |
| import json | |
| # Autentica na plataforma YouCloud e retorna a string com o AuthKey | |
| # Use o authKey para requisicoes posteriores que requerem autenticação | |
| def authenticate(url, crendential): | |
| # faz o GET para o servico de autenticacao | |
| credentialEncoded = urllib.quote_plus(credential) | |
| response = urllib2.urlopen(url + '/' + credentialEncoded) | |
| # a resposta eh uma string em Json contendo o authKey... | |
| jsonResult = response.read() | |
| # Eh importante lembrar de decodificar a resposta Json para transformá-la em string | |
| authKey = json.loads(jsonResult) | |
| return authKey | |
| # Retorna as vagas com base nos critérios | |
| def getVacancies(url, authKey, criteria, limit=10, offset=0): | |
| postDataEncoded = urllib.urlencode({'authKey' : authKey}) | |
| criteriaEncoded = urllib.quote_plus(criteria) | |
| fullUrl = url + '/' + criteriaEncoded + '/' + str(limit) + '/' + str(offset) | |
| req = urllib2.Request(fullUrl, postDataEncoded) | |
| response = urllib2.urlopen(req) | |
| jsonResult = response.read() | |
| # jsonResult conterá um array Json com as vagas retornadas | |
| result = json.loads(jsonResult) | |
| return result | |
| # url base | |
| #baseUrl = 'http://youcloud-srv/ws/amfphp/json.php/' | |
| baseUrl = 'http://youse.selecty.com.br/ws/amfphp/json.php/' | |
| # path do serviço de autenticacao | |
| authenticationServicePath = 'system.youcloud.AuthenticationService.authenticationHost' | |
| # path do serviço que retorna as vagas | |
| getVacanciesServicePath = 'hr.CurriculumWebService.getVacanciesByCriteria' | |
| url = baseUrl + authenticationServicePath | |
| # credencial para autenticacao | |
| #credential = 'cw-srv' | |
| credential = 'youse.selecty.com.br' | |
| # | |
| # 1. Autenticação na plataforma utilizando a credencial dada | |
| # | |
| print 'Autenticando na plataforma...', | |
| authKey = authenticate(url, credential) | |
| print 'OK! ' | |
| print 'AuthKey: ', authKey | |
| # | |
| # 2. Obtendo as vagas publicadas, utilizando o authKey obtido na autenticação | |
| # | |
| print 'Obtendo as vagas...', | |
| url = baseUrl + getVacanciesServicePath | |
| criteria = 'null' | |
| #criteria = "{'area' : 'Informática'}" | |
| vacancies = getVacancies(url, authKey, criteria) | |
| print 'Total de vagas retornadas: ', len(vacancies) | |
| if len(vacancies) > 0: | |
| print 'Listando as vagas:' | |
| for vacancy in vacancies: | |
| print '\t%s vaga(s) para :' % vacancy['totalVacancies'], vacancy['occupation'] | |
| else: | |
| print 'Não há vaga :(' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment