J'essaye de faire un script qui télécharge une recherche de twitter dans un format .CSV, mais, là une erreur avec mon code, n'importe quelle aide ???Comment créer un fichier CSV avec une recherche simple sur tweepy?
import tweepy
import csv
import pandas as pd
####input your credentials here
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True)
#####United Airlines
# Open/Create a file to append data
csvFile = open('test.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,q="petya",count=100,
since="2017-04-03").items():
print ("ID:", tweet.id)
print ("User ID:", tweet.user.id)
print ("Text:", tweet.text)
print ("Created:", tweet.created_at)
print ("Geo:", tweet.geo)
print ("Contributors:", tweet.contributors)
print ("Coordinates:", tweet.coordinates)
print ("Favorited:", tweet.favorited)
print ("In reply to screen name:", tweet.in_reply_to_screen_name)
print ("In reply to status ID:", tweet.in_reply_to_status_id)
print ("In reply to status ID str:", tweet.in_reply_to_status_id_str)
print ("In reply to user ID:", tweet.in_reply_to_user_id)
print ("In reply to user ID str:", tweet.in_reply_to_user_id_str)
print ("Place:", tweet.place)
print ("Retweeted:", tweet.retweeted)
print ("Retweet count:", tweet.retweet_count)
print ("Source:", tweet.source)
print ("Truncated:", tweet.truncated)
# Write a row to the CSV file. I use encode UTF-8
csvWriter.writerow([tweet.created_at, tweet.user.id, tweet.id, tweet.geo, tweet.text, tweet.contributors, tweet.favorited, tweet.source, tweet.retweeted, tweet.in_reply_to_screen_name, eet.in_reply_to_status_id_str('utf-8')])
print tweet.created_at, tweet.user.id, tweet.id, tweet.geo, tweet.text, tweet.contributors, tweet.favorited, tweet.source, tweet.retweeted, tweet.in_reply_to_screen_name, eet.in_reply_to_status_id_str
csvFile.close()
Je pense que le problème est dans la dernière partie où le csvWriter est, peut-être que je mets au texte beaucoup en une ligne? Comme je l'ai déjà dit, je suis nouveau et j'ai besoin de beaucoup d'aide.
Quelle erreur avez-vous eu? – phd