Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Programmieraufgaben WiSo 2023
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rackoll, Björn
Programmieraufgaben WiSo 2023
Commits
b90fa4c3
Commit
b90fa4c3
authored
2 years ago
by
Braun, Fabian
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
sentiment.ipynb
+79
-0
79 additions, 0 deletions
sentiment.ipynb
with
79 additions
and
0 deletions
sentiment.ipynb
0 → 100644
+
79
−
0
View file @
b90fa4c3
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "cbd16dcf-4126-482e-9ceb-092e39e5c9db",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'tweepy'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mtweepy\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtextblob\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m TextBlob\n\u001b[1;32m 4\u001b[0m consumer_key \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgRgxkWG&dU*2&J@6S*3MDXoT!pJALE38V$b462Lz\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mjGbdPvjUe\u001b[39m\u001b[38;5;124m\"\u001b[39m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'tweepy'"
]
}
],
"source": [
"import tweepy\n",
"from textblob import TextBlob\n",
"\n",
"consumer_key = \"gRgxkWG&dU*2&J@6S*3MDXoT!pJALE38V$b462Lz%jGbdPvjUe\"\n",
"consumer_secret = \"cirBr#4ykVM38mD7@6jgMwmBUHzjD$8r&Rt@7Sa^vjcXau4K9$\"\n",
"access_token = \"vSb9wJr%RjAhhvd^$qUu3U$4d#zy6pHx#XPud$Fgu&p7hzR8p!\"\n",
"access_token_secret = \"gxHkNcsJL!d9^t^J3FTVApXtHLKuh2Pm3rZA#vu^!oKJH^gU5%\"\n",
"\n",
"auth = tweepy.OAuthHandler(consumer_key, consumer_secret)\n",
"auth.set_access_token(access_token, access_token_secret)\n",
"api = tweepy.API(auth)\n",
"\n",
"search_query = \"Ampel\"\n",
"tweet_count = 1000\n",
"\n",
"tweets = tweepy.Cursor(api.search, q=search_query, lang=\"de\").items(tweet_count)\n",
"\n",
"positiveTweets = 0\n",
"negativeTweets = 0\n",
"neutralTweets = 0\n",
"\n",
"for tweet in tweets:\n",
" analysis = TextBlob(tweet.text)\n",
" polarity = analysis.sentiment.polarity\n",
"\n",
" if polarity > 0:\n",
" positiveTweets += 1\n",
" elif polarity < 0:\n",
" negativeTweets += 1\n",
" else:\n",
" neutralTweets += 1\n",
"\n",
"print(search_query, tweet_count, positiveTweets, negativeTweets, neutralTweets)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:code id:cbd16dcf-4126-482e-9ceb-092e39e5c9db tags:
```
python
import
tweepy
from
textblob
import
TextBlob
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%
"
auth
=
tweepy
.
OAuthHandler
(
consumer_key
,
consumer_secret
)
auth
.
set_access_token
(
access_token
,
access_token_secret
)
api
=
tweepy
.
API
(
auth
)
search_query
=
"
Ampel
"
tweet_count
=
1000
tweets
=
tweepy
.
Cursor
(
api
.
search
,
q
=
search_query
,
lang
=
"
de
"
).
items
(
tweet_count
)
positiveTweets
=
0
negativeTweets
=
0
neutralTweets
=
0
for
tweet
in
tweets
:
analysis
=
TextBlob
(
tweet
.
text
)
polarity
=
analysis
.
sentiment
.
polarity
if
polarity
>
0
:
positiveTweets
+=
1
elif
polarity
<
0
:
negativeTweets
+=
1
else
:
neutralTweets
+=
1
print
(
search_query
,
tweet_count
,
positiveTweets
,
negativeTweets
,
neutralTweets
)
```
%% Output
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import tweepy
2 from textblob import TextBlob
4 consumer_key = "gRgxkWG&dU
*2&J@6S*
3MDXoT!pJALE38V$b462Lz%jGbdPvjUe"
ModuleNotFoundError: No module named 'tweepy'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment