SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Downloaden Sie, um offline zu lesen
from urllib.requestimport urlopen
from bs4 import BeautifulSoup as soup
def getTwitterHandles():
# Fill in with url of page which is to be scraped
url = "https://cryptoweekly.co/100/"
# Retreives and parses page html
client = urlopen(url)
pageHtml = client.read()
pageSoup = soup(pageHtml,"html.parser")
# Adds all Twitter handles to twitterHandles list
profiles = pageSoup.findAll("div",{"class":"testimonial-wrapper"})
twitterHandles = []
for person in profiles:
twitterHandles.append(person.findAll("div",{"class":"author"}))
for i in range(len(twitterHandles)):
twitterHandles[i]=twitterHandles[i][0].findAll("a")[0].text[1:]
client.close()
return twitterHandles
if __name__ == '__main__':
getTwitterHandles()
# Modified from: https://gist.github.com/yanofsky/5436496
import tweepy #https://github.com/tweepy/tweepy
import csv
import sys
from getTwitterHandles import getTwitterHandles
# Twitter API credentials (expired,don't even try it)
consumer_key= ""
consumer_secret = ""
access_key = ""
access_secret = ""
def get_all_tweets(screen_name):
print("Gettingtweets from @" + str(screen_name))
#Twitter only allows access to a users most recent 3240 tweets with this method
#authorize twitter,initialize tweepy
auth = 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 Tweets
alltweets = []
#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 tweets
alltweets.extend(new_tweets)
#save the id of the oldest tweet less one
oldest = alltweets[-1].id - 1
#keep grabbingtweets until there are no tweets left to grab
while len(new_tweets)> 0:
print ("Gettingtweets before %s" % (oldest))
#all subsiquent requestsuse the max_id param to prevent duplicates
new_tweets = api.user_timeline(screen_name=
screen_name,count=200,max_id=oldest)
#save most recent tweets
alltweets.extend(new_tweets)
#update the id of the oldest tweet less one
oldest = alltweets[-1].id - 1
print ("...%s tweets downloadedso far" % (len(alltweets)))
#transform the tweepy tweets into a 2D array that will populate the csv
outtweets = [[tweet.id_str, tweet.created_at,tweet.text]for tweet in alltweets]
#write the csv
with open('./Tweets/%s_tweets.csv'% screen_name, 'w') as f:
writer = csv.writer(f)
writer.writerow(["id","created_at","text"])
writer.writerows(outtweets)
pass
if __name__ == '__main__':
handles = getTwitterHandles()
for handle in handles:
get_all_tweets(str(handle))
# Import modules,set styles
from helperScripts import *
import csv
import pandas as pd
import matplotlib.pyplot as plt
import numpyas np
import pickle
%matplotlib inline
plt.style.use('fivethirtyeight')
# Creates a datframe with columns:|Name|Twitter Handle|Path To Tweets|
handleNameDict = pickle.load(open("handleNamePair.pickle", "rb"))
arrayRep = np.array(list(handleNameDict.items()))
df = pd.DataFrame(arrayRep)
df = df.rename(columns={0:"Name", 1:"Twitter Handle"})
pathToTweets = []
for person in np.array(df["TwitterHandle"]):
pathToTweets.append("./Tweets/"+str(person)+"_tweets.csv")
df["Path To Tweets"] = pathToTweets
# Measures animositytowards Bitcoin Cash (0to 1, 0=low animosity,1=high animosity)
def bchAnimosityIndex(df):
# Creates search terms and counters
bitcoinCashsearch1= "bitcoincash"
bitcoinCashsearch2= "bitcoin cash"
bcashSearch = "bcash"
bitcoinCashCounter=0
bcashCounter=0
# Iterates over all tweets
for i in df["text"]:
# Increments bitcoin cash
if bitcoinCashsearch1in i.lower():
bitcoinCashCounter+=1
# Increments bitcoin cash
elif bitcoinCashsearch2in i.lower():
bitcoinCashCounter+=1
# Increments bcash
elif bcashSearch in i.lower():
bcashCounter+=1
# Calculates total # of mentions ofBCH
totalMentions = bcashCounter+bitcoinCashCounter
# If individualhas mentionedBCH,calculates animosityindex value
if totalMentions!=0:
index = bcashCounter/totalMentions
# If individualhasn't mentioned BCH,sets animosityindex value to zero
else:
index = 0
return [index,totalMentions]
# Adds columns to dataframe:|BCH Animosity|BCHMentions|
bchData = []
for i in df.iterrows():
temp = pd.read_csv(i[1][2])
bchData.append(bchAnimosityIndex(temp))
indexValue = []
bchMentions = []
for d in bchData:
indexValue.append(d[0])
bchMentions.append(d[1])
df["BCH Animosity"]= indexValue
df["BCH Mentions"]= bchMentions
ranked = df.sort_values("BCHAnimosity",ascending=False)
topTen = pd.DataFrame()
# Fills out Rank column
num = np.array([1,2,3,4,5,6,7,8,9,10])
topTen["Rank"]= num
# Fills out BCH AnimosityScore column
topTen["BCHAnimosityScore"]= np.array(ranked[ranked["BCH
Mentions"]>30].head(n=10)["BCHAnimosity"])
# Fills out Name column
topTen["Name"]= np.array(ranked[ranked["BCHMentions"]>30].head(n=10)["Name"])
# Fills out Twitter Handle column
topTen["Twitter Handle"]= np.array(ranked[ranked["BCHMentions"]>30].head(n=10)["Twitter
Handle"])

Weitere ähnliche Inhalte

Was ist angesagt?

Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_listVlad Kolesnyk
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Julien Vinber
 
introduction to Django in five slides
introduction to Django in five slides introduction to Django in five slides
introduction to Django in five slides Dan Chudnov
 
Can WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.noCan WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.noMorten Rand-Hendriksen
 
Add row in asp.net Gridview on button click using C# and vb.net
Add row in asp.net Gridview on button click using C# and vb.netAdd row in asp.net Gridview on button click using C# and vb.net
Add row in asp.net Gridview on button click using C# and vb.netVijay Saklani
 

Was ist angesagt? (10)

Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?
 
Postgre sql index
Postgre sql indexPostgre sql index
Postgre sql index
 
Esclavitud hasta-donde-puede-perdonar-dios
Esclavitud hasta-donde-puede-perdonar-diosEsclavitud hasta-donde-puede-perdonar-dios
Esclavitud hasta-donde-puede-perdonar-dios
 
introduction to Django in five slides
introduction to Django in five slides introduction to Django in five slides
introduction to Django in five slides
 
DOS
DOSDOS
DOS
 
Erik mogensen stowe
Erik mogensen stoweErik mogensen stowe
Erik mogensen stowe
 
Can WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.noCan WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.no
 
Migrare da symfony 1 a Symfony2
 Migrare da symfony 1 a Symfony2  Migrare da symfony 1 a Symfony2
Migrare da symfony 1 a Symfony2
 
Add row in asp.net Gridview on button click using C# and vb.net
Add row in asp.net Gridview on button click using C# and vb.netAdd row in asp.net Gridview on button click using C# and vb.net
Add row in asp.net Gridview on button click using C# and vb.net
 

Ähnlich wie Twitter sentiment analysis for cryptoassets

Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4DEVCON
 
Sentiment analysis- Modi, Trump, Putin
Sentiment analysis- Modi, Trump, PutinSentiment analysis- Modi, Trump, Putin
Sentiment analysis- Modi, Trump, PutinAhmed Zaidi
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”apostlion
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4DEVCON
 
Thymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.pptThymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.pptPatiento Del Mar
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalChandra Prakash Thapa
 
Flask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsFlask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsAlex Eftimie
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdffashiongallery1
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)danwrong
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4DEVCON
 
Where's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord MigrationsWhere's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord MigrationsEleanor McHugh
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPFabien Potencier
 
A Beginner's Guide to Building Data Pipelines with Luigi
A Beginner's Guide to Building Data Pipelines with LuigiA Beginner's Guide to Building Data Pipelines with Luigi
A Beginner's Guide to Building Data Pipelines with LuigiGrowth Intelligence
 
Spiffy Applications With JavaScript
Spiffy Applications With JavaScriptSpiffy Applications With JavaScript
Spiffy Applications With JavaScriptMark Casias
 
Performance Tips In Rails Development
Performance Tips In Rails DevelopmentPerformance Tips In Rails Development
Performance Tips In Rails Developmentqtlove
 

Ähnlich wie Twitter sentiment analysis for cryptoassets (20)

Finding Clojure
Finding ClojureFinding Clojure
Finding Clojure
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4
 
Sentiment analysis- Modi, Trump, Putin
Sentiment analysis- Modi, Trump, PutinSentiment analysis- Modi, Trump, Putin
Sentiment analysis- Modi, Trump, Putin
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Thymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.pptThymeleaf and Spring Controllers.ppt
Thymeleaf and Spring Controllers.ppt
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
 
Flask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshopsFlask intro - ROSEdu web workshops
Flask intro - ROSEdu web workshops
 
My First Ruby
My First RubyMy First Ruby
My First Ruby
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
 
Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4
 
Where's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord MigrationsWhere's My SQL? Designing Databases with ActiveRecord Migrations
Where's My SQL? Designing Databases with ActiveRecord Migrations
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 
A Beginner's Guide to Building Data Pipelines with Luigi
A Beginner's Guide to Building Data Pipelines with LuigiA Beginner's Guide to Building Data Pipelines with Luigi
A Beginner's Guide to Building Data Pipelines with Luigi
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Spiffy Applications With JavaScript
Spiffy Applications With JavaScriptSpiffy Applications With JavaScript
Spiffy Applications With JavaScript
 
Hunter.io scraper
Hunter.io scraperHunter.io scraper
Hunter.io scraper
 
Performance Tips In Rails Development
Performance Tips In Rails DevelopmentPerformance Tips In Rails Development
Performance Tips In Rails Development
 

Mehr von Mamoon Ismail Khalid

ATLAS - Product Requirement Document.pdf
ATLAS - Product Requirement Document.pdfATLAS - Product Requirement Document.pdf
ATLAS - Product Requirement Document.pdfMamoon Ismail Khalid
 
T(X) Innoway - Prediction Algorithm design.pdf
T(X) Innoway - Prediction Algorithm design.pdfT(X) Innoway - Prediction Algorithm design.pdf
T(X) Innoway - Prediction Algorithm design.pdfMamoon Ismail Khalid
 
Joint3DShapeMatching - a fast approach to 3D model matching using MatchALS 3...
Joint3DShapeMatching  - a fast approach to 3D model matching using MatchALS 3...Joint3DShapeMatching  - a fast approach to 3D model matching using MatchALS 3...
Joint3DShapeMatching - a fast approach to 3D model matching using MatchALS 3...Mamoon Ismail Khalid
 
Golf Swing Analysis and Posture Correction System
Golf Swing Analysis and Posture Correction SystemGolf Swing Analysis and Posture Correction System
Golf Swing Analysis and Posture Correction SystemMamoon Ismail Khalid
 
24 ideas to revive any developing country.pdf
24 ideas to revive any developing country.pdf24 ideas to revive any developing country.pdf
24 ideas to revive any developing country.pdfMamoon Ismail Khalid
 
#2 - Smart Bins - Returnable Plastic Ecosystem.pdf
#2 - Smart Bins - Returnable Plastic Ecosystem.pdf#2 - Smart Bins - Returnable Plastic Ecosystem.pdf
#2 - Smart Bins - Returnable Plastic Ecosystem.pdfMamoon Ismail Khalid
 
PyTorch to detect Humans Eating Food.pdf
PyTorch to detect Humans Eating Food.pdfPyTorch to detect Humans Eating Food.pdf
PyTorch to detect Humans Eating Food.pdfMamoon Ismail Khalid
 
Future of agriculture agriculture - technology is a necessity in 2020 and beyond
Future of agriculture agriculture - technology is a necessity in 2020 and beyondFuture of agriculture agriculture - technology is a necessity in 2020 and beyond
Future of agriculture agriculture - technology is a necessity in 2020 and beyondMamoon Ismail Khalid
 
ISA backed technology skills platform
ISA backed technology skills platformISA backed technology skills platform
ISA backed technology skills platformMamoon Ismail Khalid
 
Detect Negative and Positive sentiment in user reviews using python word2vec ...
Detect Negative and Positive sentiment in user reviews using python word2vec ...Detect Negative and Positive sentiment in user reviews using python word2vec ...
Detect Negative and Positive sentiment in user reviews using python word2vec ...Mamoon Ismail Khalid
 
Detect spam comments youtube videos and app store reviews
Detect spam comments youtube videos and app store reviewsDetect spam comments youtube videos and app store reviews
Detect spam comments youtube videos and app store reviewsMamoon Ismail Khalid
 
Start Up deal/interaction management workflow
Start Up deal/interaction management workflowStart Up deal/interaction management workflow
Start Up deal/interaction management workflowMamoon Ismail Khalid
 
LinkedIn profile Public information Scraper
LinkedIn profile Public information ScraperLinkedIn profile Public information Scraper
LinkedIn profile Public information ScraperMamoon Ismail Khalid
 
Quadcopter minimal snap trajectory generation algorithm presentation
Quadcopter minimal snap trajectory generation algorithm presentationQuadcopter minimal snap trajectory generation algorithm presentation
Quadcopter minimal snap trajectory generation algorithm presentationMamoon Ismail Khalid
 
Finra order audit trail system (OATS)
Finra order audit trail system (OATS)Finra order audit trail system (OATS)
Finra order audit trail system (OATS)Mamoon Ismail Khalid
 

Mehr von Mamoon Ismail Khalid (20)

ATLAS - Product Requirement Document.pdf
ATLAS - Product Requirement Document.pdfATLAS - Product Requirement Document.pdf
ATLAS - Product Requirement Document.pdf
 
T(X) Innoway - Prediction Algorithm design.pdf
T(X) Innoway - Prediction Algorithm design.pdfT(X) Innoway - Prediction Algorithm design.pdf
T(X) Innoway - Prediction Algorithm design.pdf
 
Joint3DShapeMatching - a fast approach to 3D model matching using MatchALS 3...
Joint3DShapeMatching  - a fast approach to 3D model matching using MatchALS 3...Joint3DShapeMatching  - a fast approach to 3D model matching using MatchALS 3...
Joint3DShapeMatching - a fast approach to 3D model matching using MatchALS 3...
 
Golf Swing Analysis and Posture Correction System
Golf Swing Analysis and Posture Correction SystemGolf Swing Analysis and Posture Correction System
Golf Swing Analysis and Posture Correction System
 
24 ideas to revive any developing country.pdf
24 ideas to revive any developing country.pdf24 ideas to revive any developing country.pdf
24 ideas to revive any developing country.pdf
 
#2 - Smart Bins - Returnable Plastic Ecosystem.pdf
#2 - Smart Bins - Returnable Plastic Ecosystem.pdf#2 - Smart Bins - Returnable Plastic Ecosystem.pdf
#2 - Smart Bins - Returnable Plastic Ecosystem.pdf
 
PyTorch to detect Humans Eating Food.pdf
PyTorch to detect Humans Eating Food.pdfPyTorch to detect Humans Eating Food.pdf
PyTorch to detect Humans Eating Food.pdf
 
Future of agriculture agriculture - technology is a necessity in 2020 and beyond
Future of agriculture agriculture - technology is a necessity in 2020 and beyondFuture of agriculture agriculture - technology is a necessity in 2020 and beyond
Future of agriculture agriculture - technology is a necessity in 2020 and beyond
 
Nano mos25
Nano mos25Nano mos25
Nano mos25
 
Real estate in blockchain (2)
Real estate in blockchain (2)Real estate in blockchain (2)
Real estate in blockchain (2)
 
Cohort analysis saa s (1)
Cohort analysis saa s (1)Cohort analysis saa s (1)
Cohort analysis saa s (1)
 
ISA backed technology skills platform
ISA backed technology skills platformISA backed technology skills platform
ISA backed technology skills platform
 
Start up valuation methods
Start up valuation methodsStart up valuation methods
Start up valuation methods
 
Analysis mvp factory
Analysis mvp factoryAnalysis mvp factory
Analysis mvp factory
 
Detect Negative and Positive sentiment in user reviews using python word2vec ...
Detect Negative and Positive sentiment in user reviews using python word2vec ...Detect Negative and Positive sentiment in user reviews using python word2vec ...
Detect Negative and Positive sentiment in user reviews using python word2vec ...
 
Detect spam comments youtube videos and app store reviews
Detect spam comments youtube videos and app store reviewsDetect spam comments youtube videos and app store reviews
Detect spam comments youtube videos and app store reviews
 
Start Up deal/interaction management workflow
Start Up deal/interaction management workflowStart Up deal/interaction management workflow
Start Up deal/interaction management workflow
 
LinkedIn profile Public information Scraper
LinkedIn profile Public information ScraperLinkedIn profile Public information Scraper
LinkedIn profile Public information Scraper
 
Quadcopter minimal snap trajectory generation algorithm presentation
Quadcopter minimal snap trajectory generation algorithm presentationQuadcopter minimal snap trajectory generation algorithm presentation
Quadcopter minimal snap trajectory generation algorithm presentation
 
Finra order audit trail system (OATS)
Finra order audit trail system (OATS)Finra order audit trail system (OATS)
Finra order audit trail system (OATS)
 

Kürzlich hochgeladen

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Kürzlich hochgeladen (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

Twitter sentiment analysis for cryptoassets

  • 1. from urllib.requestimport urlopen from bs4 import BeautifulSoup as soup def getTwitterHandles(): # Fill in with url of page which is to be scraped url = "https://cryptoweekly.co/100/" # Retreives and parses page html client = urlopen(url) pageHtml = client.read() pageSoup = soup(pageHtml,"html.parser") # Adds all Twitter handles to twitterHandles list profiles = pageSoup.findAll("div",{"class":"testimonial-wrapper"}) twitterHandles = [] for person in profiles: twitterHandles.append(person.findAll("div",{"class":"author"})) for i in range(len(twitterHandles)): twitterHandles[i]=twitterHandles[i][0].findAll("a")[0].text[1:] client.close() return twitterHandles if __name__ == '__main__': getTwitterHandles()
  • 2. # Modified from: https://gist.github.com/yanofsky/5436496 import tweepy #https://github.com/tweepy/tweepy import csv import sys from getTwitterHandles import getTwitterHandles # Twitter API credentials (expired,don't even try it) consumer_key= "" consumer_secret = "" access_key = "" access_secret = "" def get_all_tweets(screen_name): print("Gettingtweets from @" + str(screen_name)) #Twitter only allows access to a users most recent 3240 tweets with this method #authorize twitter,initialize tweepy auth = 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 Tweets
  • 3. alltweets = [] #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 tweets alltweets.extend(new_tweets) #save the id of the oldest tweet less one oldest = alltweets[-1].id - 1 #keep grabbingtweets until there are no tweets left to grab while len(new_tweets)> 0: print ("Gettingtweets before %s" % (oldest)) #all subsiquent requestsuse the max_id param to prevent duplicates new_tweets = api.user_timeline(screen_name= screen_name,count=200,max_id=oldest) #save most recent tweets alltweets.extend(new_tweets) #update the id of the oldest tweet less one oldest = alltweets[-1].id - 1 print ("...%s tweets downloadedso far" % (len(alltweets))) #transform the tweepy tweets into a 2D array that will populate the csv outtweets = [[tweet.id_str, tweet.created_at,tweet.text]for tweet in alltweets]
  • 4. #write the csv with open('./Tweets/%s_tweets.csv'% screen_name, 'w') as f: writer = csv.writer(f) writer.writerow(["id","created_at","text"]) writer.writerows(outtweets) pass if __name__ == '__main__': handles = getTwitterHandles() for handle in handles: get_all_tweets(str(handle)) # Import modules,set styles from helperScripts import * import csv import pandas as pd import matplotlib.pyplot as plt import numpyas np import pickle %matplotlib inline plt.style.use('fivethirtyeight') # Creates a datframe with columns:|Name|Twitter Handle|Path To Tweets|
  • 5. handleNameDict = pickle.load(open("handleNamePair.pickle", "rb")) arrayRep = np.array(list(handleNameDict.items())) df = pd.DataFrame(arrayRep) df = df.rename(columns={0:"Name", 1:"Twitter Handle"}) pathToTweets = [] for person in np.array(df["TwitterHandle"]): pathToTweets.append("./Tweets/"+str(person)+"_tweets.csv") df["Path To Tweets"] = pathToTweets # Measures animositytowards Bitcoin Cash (0to 1, 0=low animosity,1=high animosity) def bchAnimosityIndex(df): # Creates search terms and counters bitcoinCashsearch1= "bitcoincash" bitcoinCashsearch2= "bitcoin cash" bcashSearch = "bcash" bitcoinCashCounter=0 bcashCounter=0 # Iterates over all tweets for i in df["text"]: # Increments bitcoin cash if bitcoinCashsearch1in i.lower(): bitcoinCashCounter+=1 # Increments bitcoin cash
  • 6. elif bitcoinCashsearch2in i.lower(): bitcoinCashCounter+=1 # Increments bcash elif bcashSearch in i.lower(): bcashCounter+=1 # Calculates total # of mentions ofBCH totalMentions = bcashCounter+bitcoinCashCounter # If individualhas mentionedBCH,calculates animosityindex value if totalMentions!=0: index = bcashCounter/totalMentions # If individualhasn't mentioned BCH,sets animosityindex value to zero else: index = 0 return [index,totalMentions] # Adds columns to dataframe:|BCH Animosity|BCHMentions| bchData = [] for i in df.iterrows(): temp = pd.read_csv(i[1][2]) bchData.append(bchAnimosityIndex(temp)) indexValue = [] bchMentions = []
  • 7. for d in bchData: indexValue.append(d[0]) bchMentions.append(d[1]) df["BCH Animosity"]= indexValue df["BCH Mentions"]= bchMentions ranked = df.sort_values("BCHAnimosity",ascending=False) topTen = pd.DataFrame() # Fills out Rank column num = np.array([1,2,3,4,5,6,7,8,9,10]) topTen["Rank"]= num # Fills out BCH AnimosityScore column topTen["BCHAnimosityScore"]= np.array(ranked[ranked["BCH Mentions"]>30].head(n=10)["BCHAnimosity"]) # Fills out Name column topTen["Name"]= np.array(ranked[ranked["BCHMentions"]>30].head(n=10)["Name"]) # Fills out Twitter Handle column topTen["Twitter Handle"]= np.array(ranked[ranked["BCHMentions"]>30].head(n=10)["Twitter Handle"])