# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.9.6 64-bit
#     name: python3
# ---

import twint

import gc
gc.collect()

import twint
import nest_asyncio
nest_asyncio.apply()
# Configure
c = twint.Config()
c.Username = "DiyanetTV"
c.Limit = 300
c.Store_csv = True
c.Output = "none.csv"
twint.run.Search(c)

import nest_asyncio
nest_asyncio.apply()


def get_followers_following(username):
    dic={}
    c = twint.Config()
    c.Username = username
    c.Hide_output = True
    c.Store_object = True
    sonuc= twint.run.Lookup(c)

    fol = twint.output.users_list[:]
    dic["followers"] = fol[0].followers
    dic["following"] = fol[0].following
    return dic


tweets=[]
c = twint.Config()
c.Username = 'DiyanetTV'
c.Since = "2019-3-3"
c.Limit = 5000
c.Store_object = True
c.Store_csv = True
c.Output = "DiyanetTV.csv"
twint.run.Search(c)
tweets = twint.output.tweets_list

print(len(tweets))

# +
import io
hashtags={}
#print(type(tweets), len(tweets), type(hashtags))
# first iterate over the tweets
for t in tweets:
    #print('t:', t, type(t), t.hashtags, type(t.hashtags))
    # then iterate over the hashtags of that single tweet
    for h in t.hashtags:
        # increment the count if the hashtag already exists, otherwise initialize it to 1
        #print('h:',h,type(h),t.username)
        if(t.username in hashtags):
            if(h in hashtags[t.username]):
                hashtags[t.username][h] += 1
            else:
                hashtags[t.username][h]=1
        else:
            hashtags[t.username]={h:1}

# now save the data
with io.open('hashtags.csv', 'w', encoding="utf-8") as output:
    output.write('username,hashtag,count\n')
    for user in hashtags:
        for h in hashtags[user]:
            output.write('{},{},{}\n'.format(user, h, hashtags[user][h]))

# +
from collections import Counter

replies = twint.Config()
replies.Since = "2018-03-01"
replies.Pandas = True
replies.To = "@DiyanetTV"
twint.run.Search(replies)
df = twint.storage.panda.Tweets_df
#print(df)
# -

#print(df.head())
df.to_csv('Replies.csv', index=False)  
Replies = {x:y for x,y in zip(df['conversation_id'],df['nreplies'])}
fetchedReplies =Counter(df['conversation_id'])
#print(df[df['conversation_id']=='1243481878402723840'])
for tweet in Replies:
    print(tweet, "\t{}\t{}\t".format(Replies[tweet],fetchedReplies[tweet]))

# +
mentions={}
#print(tweets)
for t in tweets:
    #print('t:', t, type(t), t.hashtags, type(t.hashtags))
    # then iterate over the hashtags of that single tweet
    for m in t.mentions:
        #print(m, len(mentions))
        # increment the count if the hashtag already exists, otherwise initialize it to 1
        #print('h:',h,type(h),t.username)
        if(m['screen_name'] in mentions):
            mentions[m['screen_name']]+=1
        else:
            mentions[m['screen_name']]=1

print(mentions)
# -

import pandas as pd 
mentions_df= pd.DataFrame(mentions.items(), columns=['screen_name', 'count'])
mentions_df.to_csv('mentions.csv', index=False)

import sys
print(sys.executable)

# +
df_tweet=pd.read_csv('DiyanetTV.csv')
print(df_tweet.columns)
print(df_tweet.describe())
df_tweet['tweet_date']=pd.to_datetime(df_tweet['date'] + ' ' + df_tweet['time'])

df_tweet = df_tweet.rename(columns={'tweet': 'Tweet', 'tweet_date': 'Timestamp', 'hashtags': 'Subject'})
print(df_tweet.head())                      

# -

def twint2pd(columns):
    return twint.output.panda.Tweets_df[columns]


tweet_df= df_tweet[['Timestamp','username','Tweet', 'Subject','mentions','replies_count','retweets_count','likes_count']]
print(tweet_df.head())

tweet_list=tweet_df['Tweet'].tolist()

from matplotlib import pyplot
series = df_tweet[['date','likes_count']]
print(series.head())
series.plot()
pyplot.show()


def count_plot_data(df, freq):
    plot_df = df.set_index('Timestamp').groupby('Subject').resample(freq).id.count().unstack(level=0, fill_value=0)
    plot_df.index.rename('Date', inplace=True)
    plot_df = plot_df.rename_axis(None, axis='columns')
    return plot_df

StarcoderdataJupyterScriptsDedupFiltered