-
-
Save beingsane/31508c0b12c816aacca12fdbdec15e92 to your computer and use it in GitHub Desktop.
Coleção de funções de manipulação para python
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/python3.5 | |
import os | |
def importa_ssl(): | |
""" | |
Importa certificados SSL | |
""" | |
# CentOS 7.5 | |
if os.path.exists("/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt"): | |
os.environ['REQUESTS_CA_BUNDLE'] = "/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt" | |
else: | |
# Ubuntu 16.04 | |
if os.path.exists("/etc/ssl/certs/ca-certificates.crt"): | |
os.environ['REQUESTS_CA_BUNDLE'] = "/etc/ssl/certs/ca-certificates.crt" | |
def hms_to_minutes(t): | |
""" | |
Transformação de dados de hora-minuto-segundo para minutos | |
""" | |
if t == 'None': | |
return 0 | |
else: | |
h, m, s = [int(i) for i in t.split(':')] | |
return 60*h + m | |
def none_to_zero(string): | |
""" | |
Transformação de dados nulos do DB2 para inteiro | |
""" | |
if string == 'None': | |
return 0 | |
else: | |
return string | |
def dict_to_str(dictionary): | |
""" | |
Transformação de chaves e valores de um dicionario | |
em uma string separada por virgulas | |
""" | |
return ', '.join("{!s} {!s}".format(key,value) for (key,value) in dictionary.items()) | |
def dict_to_substitute_str(dictionary): | |
""" | |
Conta o tamanho de um dicionário e retorna uma string de %s | |
""" | |
return ', '.join("%s" for item in range(len(dictionary))) | |
def dictkeys_to_str(dictionary): | |
""" | |
Transformação das chaves de um dicionario | |
em uma string separada por virgulas | |
""" | |
return ', '.join("{!s}".format(key) for (key,value) in dictionary.items()) | |
def list_to_update(lista): | |
""" | |
Transformação de valores de uma lista em uma string com | |
formato de insert para sql separada por virgulas | |
""" | |
return ', '.join("{!s} = %s".format(valor) for valor in lista) | |
def list_of_list_to_list(listas): | |
""" | |
Transformação de uma lista de listas em lista simples | |
""" | |
return [ "%s" % lista for lista in listas ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment