Jump to content

Python (anaconda jupyter) saving tweets to .csv help

Go to solution Solved by 2FA,
16 minutes ago, paps511 said:

for tweet in tweewts:

 

Hey guys, 

I need help with my code for a class project. We need to scrape the most recent 1000 posts with "clinton" in them and save it to a .csv file. Everything is working except the saving to a .csv file. What am I missing? The error I am getting is that "tweets" is not defined in the writerow function, but it is a few lines above...

Thanks

from twython import Twython
import csv

csvFile = open("ryanpapera-clinton.csv", "w+")
writer = csv.writer(csvFile)

api_key = "YAR3TPkRks6VqZ7cMbR3bIALV"
api_secret = "3GHtAzgsjd95YYoTzFR3C9KQwWIv4mhYzWYMdnT8hNQzlM3yo9"
access_token_key = "807382844-XdsAO39DT8FQqoXzBNpUTpcXIdDtLJQQOsjC8T0j"
access_token_secret = "I5sLl30OxKKz6JwUEVmmUhWpz7GN0OWXl5aAK3UkfiZnf"

t = Twython(app_key=api_key, app_secret=api_secret, oauth_token=access_token_key, 
           oauth_token_secret=access_token_secret)

#Clinton
search = t.search(q='clinton', count=2)
tweets = search['statuses']

# printing all the tweets returned
for tweet in tweets:
    print(tweet['text'], '\n')

#save to .csv, 
c = csv.writer(open("ryanpapera-clinton.csv", "w+"))
for tweet in tweewts:
    writer.writerow(str(tweet("text").text))
csvFile.close()

 

CPU: Intel Core i7 8700k CPU Cooler: Corsair Hydro Series H100i Mobo:  Memory: G.Skill Ripjaws X 32GB 2133 Storage #1: 1TB 850 EVO SSD Storage #2: Western Digital Black 2TB Storage #3: Western Digital Green 4TB GPU: Gigabyte 980 Ti G1 Case: Mastercase5 PSU: EVGA 750 W G2 80+Gold Keyboard: Corsair K70 RGB Cherry MX Brown Mouse: Razer Deathadder Elite Monitor: LG 34UM94 Headset: Bose

Phone: Samsung Galaxy S9

Link to post
Share on other sites

16 minutes ago, paps511 said:

for tweet in tweewts:

 

[Out-of-date] Want to learn how to make your own custom Windows 10 image?

 

Desktop: AMD R9 3900X | ASUS ROG Strix X570-F | Radeon RX 5700 XT | EVGA GTX 1080 SC | 32GB Trident Z Neo 3600MHz | 1TB 970 EVO | 256GB 840 EVO | 960GB Corsair Force LE | EVGA G2 850W | Phanteks P400S

Laptop: Intel M-5Y10c | Intel HD Graphics | 8GB RAM | 250GB Micron SSD | Asus UX305FA

Server 01: Intel Xeon D 1541 | ASRock Rack D1541D4I-2L2T | 32GB Hynix ECC DDR4 | 4x8TB Western Digital HDDs | 32TB Raw 16TB Usable

Server 02: Intel i7 7700K | Gigabye Z170N Gaming5 | 16GB Trident Z 3200MHz

Link to post
Share on other sites

1 minute ago, DeadEyePsycho said:

 

I'm a fucking moron.

thank you

CPU: Intel Core i7 8700k CPU Cooler: Corsair Hydro Series H100i Mobo:  Memory: G.Skill Ripjaws X 32GB 2133 Storage #1: 1TB 850 EVO SSD Storage #2: Western Digital Black 2TB Storage #3: Western Digital Green 4TB GPU: Gigabyte 980 Ti G1 Case: Mastercase5 PSU: EVGA 750 W G2 80+Gold Keyboard: Corsair K70 RGB Cherry MX Brown Mouse: Razer Deathadder Elite Monitor: LG 34UM94 Headset: Bose

Phone: Samsung Galaxy S9

Link to post
Share on other sites

Just now, paps511 said:

I'm a fucking moron.

thank you

Not a problem, has happened to me a couple of times.

[Out-of-date] Want to learn how to make your own custom Windows 10 image?

 

Desktop: AMD R9 3900X | ASUS ROG Strix X570-F | Radeon RX 5700 XT | EVGA GTX 1080 SC | 32GB Trident Z Neo 3600MHz | 1TB 970 EVO | 256GB 840 EVO | 960GB Corsair Force LE | EVGA G2 850W | Phanteks P400S

Laptop: Intel M-5Y10c | Intel HD Graphics | 8GB RAM | 250GB Micron SSD | Asus UX305FA

Server 01: Intel Xeon D 1541 | ASRock Rack D1541D4I-2L2T | 32GB Hynix ECC DDR4 | 4x8TB Western Digital HDDs | 32TB Raw 16TB Usable

Server 02: Intel i7 7700K | Gigabye Z170N Gaming5 | 16GB Trident Z 3200MHz

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×