<commit_before>#!/usr/bin/env python
# -*- encoding: utf-8 -*-

"""
    Conexão do Python com banco de dados Mysql
    1- instalar o modulo python-mysql
        sudo yum -y install MySQL-python.x86_64
    2- declara o modulo "MySQLdb"
    3- Sobe o dump mysql.sql
"""
import MySQLdb
from datetime import date

connect = MySQLdb.connect(host='127.0.0.1',user='root', passwd='', db='blog')

cur = connect.cursor()

# LISTAGEM DOS DADOS
cur.execute("SELECT * FROM posts")

for post in cur.fetchall():
    if (len(post)):
        if (post[4]=='1'):
            print 'Id: %s' % (post[0])
            print 'Ttitle: %s' % (post[1])
            print 'Body: %s' % (post[2])
            print 'Created at: %s' % (post[3])
            print '\n\r'

# INSERT
query = 'INSERT INTO posts (title, body, created_at, status) VALUES ("PROXIMO TITULO POST","CORPO DO POST BLABABLA",""'
cur.execute<commit_msg>Estudos Paralelos - Conexão com banco de dados - Insert<commit_after>#!/usr/bin/env python
# -*- encoding: utf-8 -*-

"""
    Conexão do Python com banco de dados Mysql
    1- instalar o modulo python-mysql
        sudo yum -y install MySQL-python.x86_64
    2- declara o modulo "MySQLdb"
    3- Sobe o dump mysql.sql
"""
import MySQLdb
import time


connect = MySQLdb.connect(host='127.0.0.1',user='root', passwd='', db='blog')

cur = connect.cursor()

# LISTAGEM DOS DADOS
cur.execute("SELECT * FROM posts")

for post in cur.fetchall():
    if (len(post)):
        if (post[4]=='1'):
            print 'Id: %s' % (post[0])
            print 'Ttitle: %s' % (post[1])
            print 'Body: %s' % (post[2])
            print 'Created at: %s' % (post[3])
            print '\n\r'

# INSERT
dataUx = time.localtime()
datahoje ='%s-%02d-%02d 00:00:00' % (dataUx.tm_year, dataUx.tm_mon, dataUx.tm_mday)
print datahoje
#query = 'INSERT INTO posts (title, body, created_at, status) VALUES ("PROXIMO TITULO POST","CORPO DO POST BLABABLA",""'
#cur.execute
{'fraction_non_alphanumeric': 0.16065911431513905, 'fraction_numerical': 0.025746652935118436, 'mean_word_length': 2.878243512974052, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2347554', 'n_tokens_mistral': 761, 'n_tokens_neox': 705, 'n_words': 202}