Exemple #1
0
def set_database(tweet):
    # cria conexão com o banco de dados
    con = conexao.get_mysql()
    cursor = con.cursor()

    try:
        cursor.execute('INSERT INTO user_aleatorio (nome)\
			VALUES(%s)', (tweet.user.screen_name))
        print("Adicionado.....")
    except:
        # essa exceção acontece caso o tweet já exista na base de dados
        print('NÂO ADICIONADO*********')

    con.commit()
    con.close()
Exemple #2
0
def get_user_rt():
    con = conexao.get_mysql()
    cursor = con.cursor()

    sql = "use Monitor_de_noticia"
    cursor.execute(sql)
    sql = "select * from vacina_user_rt"
    cursor.execute(sql)
    consulta = cursor.fetchall()
    user_rt = [x for x in consulta]

    sql = "select user_nome from vacina_tweets_rt group by user_nome"
    cursor.execute(sql)
    consulta = cursor.fetchall()
    tweets_rt = [x[0] for x in consulta]

    user = [x for x in user_rt if x[1] not in tweets_rt]

    return user
Exemple #3
0
import tweepy
import conexao
from time import sleep

api = conexao.get_api()
con = conexao.get_mysql()
cursor = con.cursor()

username = '******'

count = 100
try:
    # Creation of query method using parameters
    tweets = tweepy.Cursor(api.user_timeline, id=username).items(count)
    tweets = [[tweet.user.screen_name, tweet.text, tweet.created_at, tweet.id]
              for tweet in tweets]

    for tweet in tweets:
        try:
            cursor.execute(
                'INSERT INTO tweet_paginas (nome, tweet, data, id_tweet) VALUES (%s, %s, %s, %s)',
                (tweet[0], tweet[1], tweet[2], tweet[3]))
            print('Adicionado')
        except:
            # essa exceção acontece caso o usuário já exista na base de dados
            print('Não adicionado')
            continue
        con.commit()

except tweepy.error.RateLimitError:
    print('RateLimitError aguardando...')