Skip to content
Snippets Groups Projects
Commit 42458266 authored by Braun, Fabian's avatar Braun, Fabian
Browse files

Upload New File

parent d9d8ddac
Branches musterlösung
No related tags found
No related merge requests found
%% Cell type:code id:cbd16dcf-4126-482e-9ceb-092e39e5c9db tags:
``` python
# Benötigt für den Zugang zur Twitter-API
import tweepy
# Benötigt für die Stimmtunsauswertung der Tweets
from textblob_de import TextBlobDE
# Fiktive Zugangsdaten
consumer_key = "gRgxkWG&dU*2&J@6S*3MDXoT!pJALE38V$b462Lz%jGbdPvjUe"
consumer_secret = "cirBr#4ykVM38mD7@6jgMwmBUHzjD$8r&Rt@7Sa^vjcXau4K9$"
access_token = "vSb9wJr%RjAhhvd^$qUu3U$4d#zy6pHx#XPud$Fgu&p7hzR8p!"
access_token_secret = "gxHkNcsJL!d9^t^J3FTVApXtHLKuh2Pm3rZA#vu^!oKJH^gU5%"
# Konfiguration des API-Zugangs
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Suchbegriff
search_query = "Ampel"
# Anzahl Tweets
tweet_count = 1000
# Anfrage an Twitter mit Suchbegriff, ANzahl Tweets und Sprache
tweets = tweepy.Cursor(api.search, q=search_query, lang="de").items(tweet_count)
# Variablendeklaration nach PEP8
positive_tweets = 0
negative_tweets = 0
neutral_tweets = 0
# Auswertung der Tweets
for tweet in tweets:
analysis = TextBlobDE(tweet.text)
polarity = analysis.sentiment.polarity
# Zählen der positiven, negativen oder neutralen Tweets
if polarity > 0:
positive_tweets += 1
elif polarity < 0:
negative_tweets += 1
else:
neutral_tweets += 1
# Ausgabe mit Suchbegriff, Anzahl Tweets gesamt, und positive, negative und neutrale
print(search_query, tweet_count, positive_tweets, negative_tweets, neutral_tweets)
```
%% Output
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 2
1 # Benötigt für den Zugang zur Twitter-API
----> 2 import tweepy
3 # Benötigt für die Stimmtunsauswertung der Tweets
4 from textblob_de import TextBlobDE
ModuleNotFoundError: No module named 'tweepy'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment