Question

In: Computer Science

Write a Python program that extracts 1000 unique links from Twitter using Tweepy. How can I...

Write a Python program that extracts 1000 unique links from Twitter using Tweepy. How can I filter out all links with Twitter domains and shortened links?

Solutions

Expert Solution

Here is the python program which will extracts 1000 unique links from Twitter using Tweepy and filter out all links with Twitter domains:-

Extraction.py

#Importing tweepy,json libraries with needed methods

import tweepy

from tweepy.streaming import StreamListener

from tweepy import OAuthHandler

from tweepy import Stream

import json

#For accessing the Twitter API

main_token = "YOUR_TOKEN" #Enter here your different access tokens in all 4 fields

main_token_secret = "SECRET_TOKEN" #Tokens can be found on twitter Developer auth

key = "CONUMER_KEY"

key_secret = "CONUMER_SECRET_KEY"

#Extracting only 1000 tweets  

total = 1000

#For printing received tweets

class StdOutListener(StreamListener):
def on_data(self, data):

#Twitter data in JSON Format

decoded = json.loads(data)

# extraction count

global total
if total <= 0: #In case of total count is 0 or less then it will exit
import sys
sys.exit()
else:
try:
for url in decoded["datas"]["links"]:
total = total - 1
print total, ':', "%s" % url["full_link"]

except KeyError:
print decoded.keys()

def on_error(self, status):

#Printing status of getting success or not
print status


if __name__ == '__main__':

#Connection with twitter using your own account values

l = StdOutListener()   
auth = OAuthHandler(key, key_secret)
auth.set_access_token(main_token, main_token_secret)
stream = Stream(auth, l)

#filter out all links with Twitter domains and you can add more shortened links

stream.filter(track=['Twitter'])

We can I filter out all links with Twitter domains and shortened links using this syntax in python:

stream.filter(track=['Twitter'],[shortened extensions])

Note: you need to specify various shortened link extensions to get filtered.

Hope you will like my work, please consider a thumbs-up or hit that like button to motivate me>3?(Hope you will do that)


Related Solutions

How can I write a Python program that runs without crashing even though it has an...
How can I write a Python program that runs without crashing even though it has an error that a compiler would have caught and how can I write a Java program that crashes even after the compiler checked it. Please add comments that explain the problem, the outcome, and what this proves in both of the programs.
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
In python using tkinter, I want to create a program. The program can have various classes...
In python using tkinter, I want to create a program. The program can have various classes and methods but I want it to have circles, triangles, and squares. Each shape movies in a certain way, like circles can move linearly, triangles can be affected by gravity, and squares can only go up and down. If the shapes get too close to one another then they disappear and a new shape appears somewhere else. I want this program to run continuously.
write an algorithm and python program using the following information. also can y How much should...
write an algorithm and python program using the following information. also can y How much should I study outside of class?                         Issue: Your fellow students need help. This is their first year in college and they need to determine how many hours they need to study to get good grades. Study Hours Per Week Per Class                    Grade 15                                                           A 12                                                           B 9                                                             C 6                                                             D 0                                                             F Project Specifications: The user enters their full name and the number...
How do I create this program? Using C++ language! Write a program that reads data from...
How do I create this program? Using C++ language! Write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global varibles are the mean, standard deviation, and the number of data entered. All other varibles must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function....ALL...
I need to write this program in Python. Write a program that displays a temperature conversion...
I need to write this program in Python. Write a program that displays a temperature conversion table for degrees Celsius and degrees Fahrenheit. The tabular format of the result should include rows for all temperatures between 70 and 270 degrees Celsius that are multiples of 10 degrees Celsius (check the sample below). Include appropriate headings on your columns. The formula for converting between degrees Celsius and degrees Fahrenheit is as follow F=(9/5C) +32 Celsius Fahrenheit 70 158 80 176 90...
Design and write a python program that reads a file of text and stores each unique...
Design and write a python program that reads a file of text and stores each unique word in some node of binary search tree while maintaining a count of the number appearance of that word. The word is stored only one time; if it appears more than once, the count is increased. The program then prints out 1) the number of distinct words stored un the tree, Function name: nword 2) the longest word in the input, function name: longest...
Can you write this program, but in python, I just wanna see what am I doing...
Can you write this program, but in python, I just wanna see what am I doing wrong. thank you Instructions: The Gas-N-Clean Service Station sells gasoline and has a car wash. Fees for the car wash are $1.25 with a gasoline purchase of $10.00 or more and $3.00 otherwise. Three kinds of gasoline are available: regular at $2.89, plus at $3.09, and super at $3.39 per gallon. User Request: Write a program that prints a statement for a customer. Analysis:...
in python Using this baseline template, write a program to input a choice from a menu...
in python Using this baseline template, write a program to input a choice from a menu def calcArea(length, width):    pass    def CalcVolumeSa(length, width, height):    pass def menu():    pass        def getValuesArea(): pass    def getValuesVolSa(): pass       def main():    menu() if __name__ == "__main__":    main() [1] - Calculate Area of rectangle [2] - calculate Volume and Surface area of Rectangle [x} - Exit Please select Option: input the appropriate values and calculate...
I need to write a program in python for a restaurant. The program should let the...
I need to write a program in python for a restaurant. The program should let the user enter a meal number, then it should display the meal name, meal price, and meal calories. Also, needs the appropriate output if the user enters an invalid meal number. I am supposed to use a dictionary, but my problem is it keeps giving me an error and telling me my menu is not defined. Not sure what I am doing wrong. print ("Welcome...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT