<jupyter_start><jupyter_text>Twitter Data Extraction<jupyter_code>import os
import tweepy #pip install tweepy
import pandas as pd
import re
from textblob_de import TextBlobDE as TextBlob
def load_file(path):
    text_file= open(path,'r')
    file_content = text_file.read()
    return file_content<jupyter_output><empty_output><jupyter_text>Twitter API Key auslesen und authentifizieren<jupyter_code># Load Twitter Api Keys From File
file_content = load_file('../../../twitter-files/credentials.txt')
sentences = file_content.split("\n")
sentences = [s.split("=") for s in sentences]
# Authentifizierung
consumer_key = sentences[0][1]
consumer_secret = sentences[1][1]
access_token = sentences[2][1]
access_token_secret = sentences[3][1]

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)<jupyter_output><empty_output><jupyter_text>Eigene Timeline ausgeben<jupyter_code># Eigene Twitter Timeline ausgeben
public_tweets = api.home_timeline()
for tweet in public_tweets:
    print(tweet.text)<jupyter_output><empty_output><jupyter_text>Tweets zu einem Hashtag auslesen<jupyter_code>public_tweets = api.search('#chemnitz', rpp=20, lang="de")
x = []
for tweet in public_tweets:
    x.append(tweet.text)
    print(tweet.text + "\n\n")
    
#Sentiment Analysis on Tweets
# analysis = TextBlob(tweet.text)
# print(analysis.sentiment)
# print("")
x[14]<jupyter_output><empty_output><jupyter_text>Tweet zu einer Tweet ID auslesen<jupyter_code>tweet = api.get_status("375157302846062593")
print(tweet.text)<jupyter_output>Mirabellen frisch aus dem Garten ❤ #obst #ernte #healthy #herbst #yummy #mirabellen http://t.co/u5poZLbewJ<jupyter_text>Tweets herunterladen<jupyter_code># Tweets herunterladen
tweet_content = []
for tweet_id in range(75):
#     print(tweet_corpus["Tweet ID"][tweet_id])
    try:
        tweet_content.append(api.get_status(tweet_corpus["Tweet ID"][tweet_id]).text)
    except Exception:
# Tweets herunterladen
tweet_content = []
for tweet_id in range(75):
    tweet_content.append(api.get_status(tweet_corpus["Tweet ID"][tweet_id]).text)

print(tweet_content[0])
print(len(tweet_content))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11936936936936937, 'fraction_numerical': 0.016216216216216217, 'mean_word_length': 7.165441176470588, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '360487', 'license': 'MIT', 'n_tokens_mistral': 859, 'n_tokens_neox': 831, 'n_words': 148, 'path': 'Deep Learning/Twitter Data/Twitter Data Extraction.ipynb', 'repo_name': 'florianfricke/data_science_jupyter_notebooks', 'size': '2220'}