def stalk_infinito(db): twitter = queries.conectar() ultimo_id = -1 ids = list() for i in seguir: ids.append("-1") idx = 0 while 1: for patron in seguir: sleep(0.1) # try: # ultimo_id = db.tweets.find({'mensaje':{'$regex':patron}}).sort("tweet_id",pymongo.ASCENDING).limit(1)[0]['tweet_id'] # except: # ultimo_id = -1 ultimo_id = ids[idx] # print("ultimo="+ultimo_id) (twitter, agregar_t) = queries.get_tweets(twitter, patron, tweets_por_query, ultimo_id) # for i in agregar_t: # print(i['tweet_id']) print("agregar n elementos = " + str(len(agregar_t))) if len(agregar_t) > 0: ids[idx] = str(int(agregar_t[len(agregar_t) - 1]["tweet_id"]) - 1) # print("Nuevo ultimo=" + ids[idx]) print("Voy = " + str(idx) + " id=" + ids[idx] + "\n\n--------------------") idx += 1 idx %= len(seguir) add_tweets(db, agregar_t)
def stalk_infinito_nuevos(db): twitter = queries.conectar() while 1: for patron in seguir: # print(patron) sleep(0.1) try: ultimo_id = ( db.tweets.find({"mensaje": {"$regex": patron}}) .sort("tweet_id", pymongo.DESCENDING) .limit(1)[0]["tweet_id"] ) except: ultimo_id = -1 ultimo_id = str(int(ultimo_id)) agregar_t = queries.get_tweets_from_since(twitter, patron, 50, ultimo_id) for i in agregar_t: print(i["tweet_id"]) # while(1): # pass print(len(agregar_t)) add_tweets(db, agregar_t)