示例#1
0
next_results = {"q": q, "count": 100}
if result_type is not None:
    next_results["result_type"] = result_type
if max_id is not None:
    next_results["max_id"] = max_id
if until is not None:
    next_results["until"] = until
if lang is not None:
    next_results["lang"] = lang
db.cursor = db.conn.cursor()
try:
    for i in range(0, n):
        print("Request: %d" % (i+1,))
        result = twitter.search(**next_results)
        columns, update_columns, tweets = fix_tweets(result)
        db.upsert(table=table, columns=columns, update_columns=update_columns, values=tweets)

        if 'next_results' in result['search_metadata']:
            next_results = str(result['search_metadata']['next_results'][1:]).split('&')
            aux = dict()
            for x in next_results:
                x = x.split("=")
                aux[x[0]] = x[1]
            next_results = aux
            next_results['q'] = q
        else:
            break
except Exception as e:
    print(e)
finally:
    db.conn.commit()
示例#2
0
if result_type is not None:
    next_results["result_type"] = result_type
if max_id is not None:
    next_results["max_id"] = max_id
if until is not None:
    next_results["until"] = until
if lang is not None:
    next_results["lang"] = lang
db.cursor = db.conn.cursor()
try:
    for i in range(0, n):
        print("Request: %d" % (i + 1, ))
        result = twitter.search(**next_results)
        columns, update_columns, tweets = fix_tweets(result)
        db.upsert(table=table,
                  columns=columns,
                  update_columns=update_columns,
                  values=tweets)

        if 'next_results' in result['search_metadata']:
            next_results = str(
                result['search_metadata']['next_results'][1:]).split('&')
            aux = dict()
            for x in next_results:
                x = x.split("=")
                aux[x[0]] = x[1]
            next_results = aux
            next_results['q'] = q
        else:
            break
except Exception as e:
    print(e)