SlideShare a Scribd company logo
1 of 1
Download to read offline
Write a Python program that extracts 1000 unique links from Twitter using Tweepy. Desired
output only has screen name and extended urls.
Solution
import tweepy /tweepy/tweepy
import tweepy /tweepy/tweepyimport csv#Twitter API credentialsconsumer_key =
""consumer_secret = ""access_key = ""access_secret = ""def
get_all_tweets(screen_name):#Twitter only allows access to a users most recent 3240 tweets
with this method#authorize twitter, initialize tweepyauth =
tweepy.OAuthHandler(consumer_key, consumer_secret)auth.set_access_token(access_key,
access_secret)api = tweepy.API(auth)#initialize a list to hold all the tweepy Tweetsalltweets =
[]#make initial request for most recent tweets (200 is the maximum allowed count)new_tweets =
api.user_timeline(screen_name = screen_name,count=200)#save most recent
tweetsalltweets.extend(new_tweets)#save the id of the oldest tweet less oneoldest = alltweets[-
1].id - 1#keep grabbing tweets until there are no tweets left to grabwhile len(new_tweets) >
0:print "getting tweets before %s" % (oldest)#all subsiquent requests use the max_id param to
prevent duplicatesnew_tweets = api.user_timeline(screen_name =
screen_name,count=200,max_id=oldest)#save most recent
tweetsalltweets.extend(new_tweets)#update the id of the oldest tweet less oneoldest =
alltweets[-1].id - 1print "...%s tweets downloaded so far" % (len(alltweets))#transform the
tweepy tweets into a 2D array that will populate the csvouttweets = [[tweet.id_str,
tweet.created_at, tweet.text.encode("utf-8")] for tweet in alltweets]#write the csvwith
open('%s_tweets.csv' % screen_name, 'wb') as f:writer = csv.writer(f)
writer.writerow(["id","created_at","text"])writer.writerows(outtweets)passif __name__ ==
'__main__':#pass in the username of the account you want to
downloadget_all_tweets("J_tsar")

More Related Content

Similar to Write a Python program that extracts 1000 unique links from Twitter .pdf

How to get data from twitter (by hnnrrhm)
How to get data from twitter (by hnnrrhm)How to get data from twitter (by hnnrrhm)
How to get data from twitter (by hnnrrhm)Hani Nurrahmi
 
Streaming twitter data using kafka
Streaming twitter data using kafkaStreaming twitter data using kafka
Streaming twitter data using kafkaKiran Krishna
 
TwitterKitではじめる OAuthスピードクッキング
TwitterKitではじめる OAuthスピードクッキングTwitterKitではじめる OAuthスピードクッキング
TwitterKitではじめる OAuthスピードクッキングTakashi Nojima
 
Social media analysis in R using twitter API
Social media analysis in R using twitter API Social media analysis in R using twitter API
Social media analysis in R using twitter API Mohd Shadab Alam
 
Tips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTim Cull
 
Thymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.pptThymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.pptPatiento Del Mar
 
Development of Twitter Application #3 - OAuth
Development of Twitter Application #3 - OAuthDevelopment of Twitter Application #3 - OAuth
Development of Twitter Application #3 - OAuthMyungjin Lee
 
Twitter APIs for #MediaHackday
Twitter APIs for #MediaHackdayTwitter APIs for #MediaHackday
Twitter APIs for #MediaHackdayAndy Piper
 
Lets have some fun with twilio open tok
Lets have some fun with   twilio open tokLets have some fun with   twilio open tok
Lets have some fun with twilio open tokmirahman
 
Intro to developing for @twitterapi (updated)
Intro to developing for @twitterapi (updated)Intro to developing for @twitterapi (updated)
Intro to developing for @twitterapi (updated)Raffi Krikorian
 
Let's read code: the python-requests library
Let's read code: the python-requests libraryLet's read code: the python-requests library
Let's read code: the python-requests librarySusan Tan
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + djangoNina Zakharenko
 
DEFCON 23 - Miaubiz - put on your tinfo_t hat
DEFCON 23 - Miaubiz - put on your tinfo_t hatDEFCON 23 - Miaubiz - put on your tinfo_t hat
DEFCON 23 - Miaubiz - put on your tinfo_t hatFelipe Prado
 
Building a Production-ready Predictive App for Customer Service - Alex Ingerm...
Building a Production-ready Predictive App for Customer Service - Alex Ingerm...Building a Production-ready Predictive App for Customer Service - Alex Ingerm...
Building a Production-ready Predictive App for Customer Service - Alex Ingerm...PAPIs.io
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)danwrong
 

Similar to Write a Python program that extracts 1000 unique links from Twitter .pdf (20)

How to get data from twitter (by hnnrrhm)
How to get data from twitter (by hnnrrhm)How to get data from twitter (by hnnrrhm)
How to get data from twitter (by hnnrrhm)
 
Streaming twitter data using kafka
Streaming twitter data using kafkaStreaming twitter data using kafka
Streaming twitter data using kafka
 
PyLecture2 -NetworkX-
PyLecture2 -NetworkX-PyLecture2 -NetworkX-
PyLecture2 -NetworkX-
 
TwitterKitではじめる OAuthスピードクッキング
TwitterKitではじめる OAuthスピードクッキングTwitterKitではじめる OAuthスピードクッキング
TwitterKitではじめる OAuthスピードクッキング
 
Social media analysis in R using twitter API
Social media analysis in R using twitter API Social media analysis in R using twitter API
Social media analysis in R using twitter API
 
Tips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applicationsTips and tricks for building api heavy ruby on rails applications
Tips and tricks for building api heavy ruby on rails applications
 
Api Doc
Api DocApi Doc
Api Doc
 
Api Doc
Api DocApi Doc
Api Doc
 
Thymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.pptThymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.ppt
 
Development of Twitter Application #3 - OAuth
Development of Twitter Application #3 - OAuthDevelopment of Twitter Application #3 - OAuth
Development of Twitter Application #3 - OAuth
 
Twitter APIs for #MediaHackday
Twitter APIs for #MediaHackdayTwitter APIs for #MediaHackday
Twitter APIs for #MediaHackday
 
Lets have some fun with twilio open tok
Lets have some fun with   twilio open tokLets have some fun with   twilio open tok
Lets have some fun with twilio open tok
 
Intro to developing for @twitterapi (updated)
Intro to developing for @twitterapi (updated)Intro to developing for @twitterapi (updated)
Intro to developing for @twitterapi (updated)
 
Let's read code: the python-requests library
Let's read code: the python-requests libraryLet's read code: the python-requests library
Let's read code: the python-requests library
 
XML External Entity (XXE)
XML External Entity (XXE)XML External Entity (XXE)
XML External Entity (XXE)
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
DEFCON 23 - Miaubiz - put on your tinfo_t hat
DEFCON 23 - Miaubiz - put on your tinfo_t hatDEFCON 23 - Miaubiz - put on your tinfo_t hat
DEFCON 23 - Miaubiz - put on your tinfo_t hat
 
Building a Production-ready Predictive App for Customer Service - Alex Ingerm...
Building a Production-ready Predictive App for Customer Service - Alex Ingerm...Building a Production-ready Predictive App for Customer Service - Alex Ingerm...
Building a Production-ready Predictive App for Customer Service - Alex Ingerm...
 
Mining Georeferenced Data
Mining Georeferenced DataMining Georeferenced Data
Mining Georeferenced Data
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
 

More from fathimafancyjeweller

Which of the following statements about financial intermediaries is .pdf
Which of the following statements about financial intermediaries is .pdfWhich of the following statements about financial intermediaries is .pdf
Which of the following statements about financial intermediaries is .pdffathimafancyjeweller
 
Why must each network router interface belong to a different network.pdf
Why must each network router interface belong to a different network.pdfWhy must each network router interface belong to a different network.pdf
Why must each network router interface belong to a different network.pdffathimafancyjeweller
 
What are the similarities and differences between the seppuku of the.pdf
What are the similarities and differences between the seppuku of the.pdfWhat are the similarities and differences between the seppuku of the.pdf
What are the similarities and differences between the seppuku of the.pdffathimafancyjeweller
 
Which of the following are considered withdrawals from an economy.pdf
Which of the following are considered withdrawals from an economy.pdfWhich of the following are considered withdrawals from an economy.pdf
Which of the following are considered withdrawals from an economy.pdffathimafancyjeweller
 
What measures have the EU (or member nations) taken to mitigate the .pdf
What measures have the EU (or member nations) taken to mitigate the .pdfWhat measures have the EU (or member nations) taken to mitigate the .pdf
What measures have the EU (or member nations) taken to mitigate the .pdffathimafancyjeweller
 
What types of powers are given to the states by the Constitution.pdf
What types of powers are given to the states by the Constitution.pdfWhat types of powers are given to the states by the Constitution.pdf
What types of powers are given to the states by the Constitution.pdffathimafancyjeweller
 
Using the balanced equations given below, determine the overall mola.pdf
Using the balanced equations given below, determine the overall mola.pdfUsing the balanced equations given below, determine the overall mola.pdf
Using the balanced equations given below, determine the overall mola.pdffathimafancyjeweller
 
True or false Income statement profit and loss statement shows com.pdf
True or false Income statement profit and loss statement shows com.pdfTrue or false Income statement profit and loss statement shows com.pdf
True or false Income statement profit and loss statement shows com.pdffathimafancyjeweller
 
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdfThomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdffathimafancyjeweller
 
The government uses part of payroll taxes to pay for Social Security..pdf
The government uses part of payroll taxes to pay for Social Security..pdfThe government uses part of payroll taxes to pay for Social Security..pdf
The government uses part of payroll taxes to pay for Social Security..pdffathimafancyjeweller
 
The financial statements are prepared from the unadjusted trial balan.pdf
The financial statements are prepared from the unadjusted trial balan.pdfThe financial statements are prepared from the unadjusted trial balan.pdf
The financial statements are prepared from the unadjusted trial balan.pdffathimafancyjeweller
 
Should the US conform to international standardsSolutionYes, .pdf
Should the US conform to international standardsSolutionYes, .pdfShould the US conform to international standardsSolutionYes, .pdf
Should the US conform to international standardsSolutionYes, .pdffathimafancyjeweller
 
Research and describe a tool that can be used to test for web server.pdf
Research and describe a tool that can be used to test for web server.pdfResearch and describe a tool that can be used to test for web server.pdf
Research and describe a tool that can be used to test for web server.pdffathimafancyjeweller
 
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdfQuestion 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdffathimafancyjeweller
 
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdf
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdfQuestion 1. Dscribe the change you observed when you added 1 mL of 0.pdf
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdffathimafancyjeweller
 
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdf
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdfProve that a group of order 255 is a cyclic.SolutionLet G be a .pdf
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdffathimafancyjeweller
 
Choose one field such as academia, health, consulting, business, man.pdf
Choose one field such as academia, health, consulting, business, man.pdfChoose one field such as academia, health, consulting, business, man.pdf
Choose one field such as academia, health, consulting, business, man.pdffathimafancyjeweller
 
An intercalating agent 1. Inserts between base pairs of the two str.pdf
An intercalating agent 1. Inserts between base pairs of the two str.pdfAn intercalating agent 1. Inserts between base pairs of the two str.pdf
An intercalating agent 1. Inserts between base pairs of the two str.pdffathimafancyjeweller
 
a trait is considered discrete when 1-The traits are intermediat.pdf
a trait is considered discrete when 1-The traits are intermediat.pdfa trait is considered discrete when 1-The traits are intermediat.pdf
a trait is considered discrete when 1-The traits are intermediat.pdffathimafancyjeweller
 
Please show your input and output screenshot of matlab. Show all wor.pdf
Please show your input and output screenshot of matlab. Show all wor.pdfPlease show your input and output screenshot of matlab. Show all wor.pdf
Please show your input and output screenshot of matlab. Show all wor.pdffathimafancyjeweller
 

More from fathimafancyjeweller (20)

Which of the following statements about financial intermediaries is .pdf
Which of the following statements about financial intermediaries is .pdfWhich of the following statements about financial intermediaries is .pdf
Which of the following statements about financial intermediaries is .pdf
 
Why must each network router interface belong to a different network.pdf
Why must each network router interface belong to a different network.pdfWhy must each network router interface belong to a different network.pdf
Why must each network router interface belong to a different network.pdf
 
What are the similarities and differences between the seppuku of the.pdf
What are the similarities and differences between the seppuku of the.pdfWhat are the similarities and differences between the seppuku of the.pdf
What are the similarities and differences between the seppuku of the.pdf
 
Which of the following are considered withdrawals from an economy.pdf
Which of the following are considered withdrawals from an economy.pdfWhich of the following are considered withdrawals from an economy.pdf
Which of the following are considered withdrawals from an economy.pdf
 
What measures have the EU (or member nations) taken to mitigate the .pdf
What measures have the EU (or member nations) taken to mitigate the .pdfWhat measures have the EU (or member nations) taken to mitigate the .pdf
What measures have the EU (or member nations) taken to mitigate the .pdf
 
What types of powers are given to the states by the Constitution.pdf
What types of powers are given to the states by the Constitution.pdfWhat types of powers are given to the states by the Constitution.pdf
What types of powers are given to the states by the Constitution.pdf
 
Using the balanced equations given below, determine the overall mola.pdf
Using the balanced equations given below, determine the overall mola.pdfUsing the balanced equations given below, determine the overall mola.pdf
Using the balanced equations given below, determine the overall mola.pdf
 
True or false Income statement profit and loss statement shows com.pdf
True or false Income statement profit and loss statement shows com.pdfTrue or false Income statement profit and loss statement shows com.pdf
True or false Income statement profit and loss statement shows com.pdf
 
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdfThomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
 
The government uses part of payroll taxes to pay for Social Security..pdf
The government uses part of payroll taxes to pay for Social Security..pdfThe government uses part of payroll taxes to pay for Social Security..pdf
The government uses part of payroll taxes to pay for Social Security..pdf
 
The financial statements are prepared from the unadjusted trial balan.pdf
The financial statements are prepared from the unadjusted trial balan.pdfThe financial statements are prepared from the unadjusted trial balan.pdf
The financial statements are prepared from the unadjusted trial balan.pdf
 
Should the US conform to international standardsSolutionYes, .pdf
Should the US conform to international standardsSolutionYes, .pdfShould the US conform to international standardsSolutionYes, .pdf
Should the US conform to international standardsSolutionYes, .pdf
 
Research and describe a tool that can be used to test for web server.pdf
Research and describe a tool that can be used to test for web server.pdfResearch and describe a tool that can be used to test for web server.pdf
Research and describe a tool that can be used to test for web server.pdf
 
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdfQuestion 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
 
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdf
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdfQuestion 1. Dscribe the change you observed when you added 1 mL of 0.pdf
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdf
 
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdf
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdfProve that a group of order 255 is a cyclic.SolutionLet G be a .pdf
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdf
 
Choose one field such as academia, health, consulting, business, man.pdf
Choose one field such as academia, health, consulting, business, man.pdfChoose one field such as academia, health, consulting, business, man.pdf
Choose one field such as academia, health, consulting, business, man.pdf
 
An intercalating agent 1. Inserts between base pairs of the two str.pdf
An intercalating agent 1. Inserts between base pairs of the two str.pdfAn intercalating agent 1. Inserts between base pairs of the two str.pdf
An intercalating agent 1. Inserts between base pairs of the two str.pdf
 
a trait is considered discrete when 1-The traits are intermediat.pdf
a trait is considered discrete when 1-The traits are intermediat.pdfa trait is considered discrete when 1-The traits are intermediat.pdf
a trait is considered discrete when 1-The traits are intermediat.pdf
 
Please show your input and output screenshot of matlab. Show all wor.pdf
Please show your input and output screenshot of matlab. Show all wor.pdfPlease show your input and output screenshot of matlab. Show all wor.pdf
Please show your input and output screenshot of matlab. Show all wor.pdf
 

Recently uploaded

FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 

Recently uploaded (20)

FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 

Write a Python program that extracts 1000 unique links from Twitter .pdf

  • 1. Write a Python program that extracts 1000 unique links from Twitter using Tweepy. Desired output only has screen name and extended urls. Solution import tweepy /tweepy/tweepy import tweepy /tweepy/tweepyimport csv#Twitter API credentialsconsumer_key = ""consumer_secret = ""access_key = ""access_secret = ""def get_all_tweets(screen_name):#Twitter only allows access to a users most recent 3240 tweets with this method#authorize twitter, initialize tweepyauth = tweepy.OAuthHandler(consumer_key, consumer_secret)auth.set_access_token(access_key, access_secret)api = tweepy.API(auth)#initialize a list to hold all the tweepy Tweetsalltweets = []#make initial request for most recent tweets (200 is the maximum allowed count)new_tweets = api.user_timeline(screen_name = screen_name,count=200)#save most recent tweetsalltweets.extend(new_tweets)#save the id of the oldest tweet less oneoldest = alltweets[- 1].id - 1#keep grabbing tweets until there are no tweets left to grabwhile len(new_tweets) > 0:print "getting tweets before %s" % (oldest)#all subsiquent requests use the max_id param to prevent duplicatesnew_tweets = api.user_timeline(screen_name = screen_name,count=200,max_id=oldest)#save most recent tweetsalltweets.extend(new_tweets)#update the id of the oldest tweet less oneoldest = alltweets[-1].id - 1print "...%s tweets downloaded so far" % (len(alltweets))#transform the tweepy tweets into a 2D array that will populate the csvouttweets = [[tweet.id_str, tweet.created_at, tweet.text.encode("utf-8")] for tweet in alltweets]#write the csvwith open('%s_tweets.csv' % screen_name, 'wb') as f:writer = csv.writer(f) writer.writerow(["id","created_at","text"])writer.writerows(outtweets)passif __name__ == '__main__':#pass in the username of the account you want to downloadget_all_tweets("J_tsar")