Twint: Using Store_csv

Created on 1 May 2018  路  4Comments  路  Source: twintproject/twint

I am interested in using Twint in its module form to scrape some user data into a CSV form. Currently, I am using the following test code:

import twint

# Configure
c = twint.Config()

c.Store_csv = True
# equivalent to `-s` bitcoin
c.Search = "Trump"
# Custom output format

c.Format = "Tweet id: {id} | Username: {username}"

# Run
twint.Search(c)

Right now, I am unsure of how exactly to use the Store_csv function, and am not seeing any output besides in my terminal - am I able to specify the name of the CSV file, and how do I ensure that it is actually running?

enhancement question

Most helpful comment

@wagerpascal Okay, I've added support for custom CSV fields. This was a really good idea.

Here's an example of how to incorporate it:

#!/usr/bin/python3
import twint

c = twint.Config()

c.Username = "twitter"
c.Store_csv = True
# CSV Fieldnames
c.Custom_csv = ["id", "user_id", "username", "tweet"]
c.Output = "twitter.csv"

twint.Search(c)

More info is on the wiki if you need.

All 4 comments

Hi,

You need to specify a file with c.Output. So your code should look something like this:

import twint

c = twint.Configure()

c.Store_csv = True
c.Output = "trump.csv"
c.Search = "Trump"

twint.Search(c)

@haccer Thanks for the quick response!
I have one more question regarding the code I posted- is c.Format able to alter the format/content of the CSV file, or is it limited to only the terminal output?

@wagerpascal no but I think i can make that

@wagerpascal Okay, I've added support for custom CSV fields. This was a really good idea.

Here's an example of how to incorporate it:

#!/usr/bin/python3
import twint

c = twint.Config()

c.Username = "twitter"
c.Store_csv = True
# CSV Fieldnames
c.Custom_csv = ["id", "user_id", "username", "tweet"]
c.Output = "twitter.csv"

twint.Search(c)

More info is on the wiki if you need.

Was this page helpful?
0 / 5 - 0 ratings