Skip to content

Instantly share code, notes, and snippets.

View eder-projetos-dev's full-sized avatar

Éder Luís Britto Garcia eder-projetos-dev

View GitHub Profile
@eder-projetos-dev
eder-projetos-dev / comentarios-ordem-cronologica-reversa.py
Last active February 26, 2023 21:08
Python - Exibindo comentários em ordem cronológica reversa
"""
Exibindo comentários em ordem cronológica reversa.
Os mais recentes aparecem primeiro.
https://docs.python.org/3/howto/sorting.html
"""
comentarios = [
['2023-1-29 11:03:00',"Agora entendi o problema"],
['2023-1-29 11:04:01',"Quase finalizando"],
['2022-12-29 8:32:49',"Recebi sua mensagem"],
['2022-12-30 4:14:58',"Ainda não entendi o problema"],
@eder-projetos-dev
eder-projetos-dev / lendo_argumentos.py
Last active February 26, 2023 21:08
Python - Lendo a lista de argumentos passados para o script
import sys
try:
if sys.argv[1] in sys.argv: # Caso exista argumento 1
match sys.argv[1]:
case "oi":
print("\nOlá pessoa!")
case "tchau":
print("\nTchau, até logo!")
case _:
@eder-projetos-dev
eder-projetos-dev / usuarios.py
Last active February 26, 2023 21:08
Python - Conexão com mysql e query retornando string
import mysql.connector
mydb = mysql.connector.connect(
host="127.0.1.1", # ip do banco
user="usuario",
passwd="senha",
database="banco_glpi"
)
mycursor = mydb.cursor()
@eder-projetos-dev
eder-projetos-dev / exemplo_decorator.py
Last active February 26, 2023 21:07 — forked from marcoscastro/exemplo_decorator.py
Python - Exemplo simples de decorator
def maiuscula(funcao):
def wrapper(texto): # função que modifica
return funcao(texto.upper()) # transforma pra maiúscula
return wrapper # retorna a função modificadora
@maiuscula
def imprimir_mensagem(nome):
print(f"Olá {nome}, \nSeja bem vindo!")
@eder-projetos-dev
eder-projetos-dev / html_parser_exemplo.py
Last active February 26, 2023 21:06
Python - What is the HTML parser?
from html.parser import HTMLParser
class Parser(HTMLParser):
# method to append the start tag to the list start_tags.
def handle_starttag(self, tag, attrs):
global start_tags
start_tags.append(tag)
# method to append the end tag to the list end_tags.
@eder-projetos-dev
eder-projetos-dev / parser_bs4.py
Last active February 26, 2023 21:05
Python - Parser html com BeautifulSoup
from bs4 import BeautifulSoup
html = 'lt;p><span style="font-weight: 400;">Você não teve o e-mail pessoal criado por falta de informações, para a criação você deve abrir um novo chamado com os seguintes dados:</span></p><p><strong>CPF -</strong></p><p><strong>NOME COMPLETO - </strong></p><p><strong>MATRÍCULA -</strong></p><p><strong>CARGO -</strong></p><p><strong>TELEFONE -</strong></p><p><strong>SETOR -</strong></p>'
soup = BeautifulSoup(html, 'html5lib')
print(soup.get_text())
@eder-projetos-dev
eder-projetos-dev / gist:66d589ce77b902045fc198a3a60f6ef2
Last active February 26, 2023 21:05
GIT - How to Checkout/Clone From a Specific Git Commit Id (SHA)
# Checkout From Specific Git Commit ID
git log
# Copy the commit (SHA) id and checkout using the following command.
git checkout 28cd74decb47d8a5294eb59e793cb24a0f242e9e
# You can also use the short form of the SHA ID from the start, as shown below.
@eder-projetos-dev
eder-projetos-dev / gist:e36cbeb306cc4305aca9b7ceedf2a867
Last active February 26, 2023 21:04
Python - Abrir URL com webbrowser
import webbrowser
webbrowser.open("https://github.com/eder-projetos-dev")
@eder-projetos-dev
eder-projetos-dev / tuto-virtualenv.txt
Last active March 5, 2023 18:48
Python - Instalação e criação de ambientes virtuais (venv) no Linux e no Windows
### Instalando python3-venv
sudo apt install -y python3-venv
### Criando my_env
cd ~
@eder-projetos-dev
eder-projetos-dev / gist:4db6bd23191f27f323f4e82bf899af06
Last active February 26, 2023 21:03
Python - Arquivo requirements.txt
# Criar o arquivo requirements com o freeze
pip freeze > requirements.txt
# Instalar as dependências utilizando o requirements
pip install -r requirements.txt