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

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
 
Case study cybersecurity industry birth and growth
Case study cybersecurity industry birth and growth Case study cybersecurity industry birth and growth
Case study cybersecurity industry birth and growth Mamoon Ismail Khalid
 
Design Document - Remote Solar Monitoring and Bateery Optimzation System
Design Document - Remote Solar Monitoring and Bateery Optimzation SystemDesign Document - Remote Solar Monitoring and Bateery Optimzation System
Design Document - Remote Solar Monitoring and Bateery Optimzation SystemMamoon Ismail Khalid
 

Mehr von Mamoon Ismail Khalid (20)

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)
 
Case study cybersecurity industry birth and growth
Case study cybersecurity industry birth and growth Case study cybersecurity industry birth and growth
Case study cybersecurity industry birth and growth
 
Design Document - Remote Solar Monitoring and Bateery Optimzation System
Design Document - Remote Solar Monitoring and Bateery Optimzation SystemDesign Document - Remote Solar Monitoring and Bateery Optimzation System
Design Document - Remote Solar Monitoring and Bateery Optimzation System
 

Kürzlich hochgeladen

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Kürzlich hochgeladen (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

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"])