Ejemplo n.º 1
0
from crunch import crunch_data
crunched_data, week, year = crunch_data(weeks=4, 
                                        on="week", 
                                        name_threshold=500,
                                        dropNaNs=False)
print crunched_data

data = {}
for index, row in crunched_data.iterrows():
    data[index] = {#'color': plt.cm.get_cmap('spring')(row.values[0]), 
                   'color': '#000000',
                   'percent': int(row.values[-2]*100),
                   'deviation': abs(50 - int(row.values[-2]*100))}

from circlegraph import make_figure
filename = make_figure(data, text="vecka {}".format(week), year=year, font="Latin Modern Mono")

twitter_handles = {'dn.se': '@Dagensnyheter', 'expressen.se': '@Expressen',
                   'svd.se': '@SvD', 'etc.se': '@ETC_redaktionen',
                   'svt.se': '@SVT', 'aftonbladet.se': '@Aftonbladet',
                   'di.se': '@dagensindustri'}

# Get best and worst
best = sorted(data.iteritems(), key=lambda e: e[1]['deviation'])[0][0]
best_percent = sorted(data.iteritems(), key=lambda e: e[1]['deviation'])[0][1]['percent']
worst = sorted(data.iteritems(), key=lambda e: e[1]['deviation'])[-1][0]
worst_percent = sorted(data.iteritems(), key=lambda e: e[1]['deviation'])[-1][1]['percent']

tweet_to_worst = 'Vecka {week} hade {worst} {worst_percent} % kvinnor i sina texter och var därmed sämst denna vecka. Bäst var {best} med {best_percent} %.'.format(week=week, worst=twitter_handles[worst], worst_percent=worst_percent, best=twitter_handles[best], best_percent=best_percent)
print tweet_to_worst
assert len(tweet_to_worst) < 140
Ejemplo n.º 2
0
auth = tweepy.OAuthHandler(conf.consumer_key, conf.consumer_secret)
auth.set_access_token(conf.access_token, conf.access_token_secret)
api = tweepy.API(auth)

from crunch import crunch_data
crunched_data, week, year = crunch_data()

data = {}
for index, row in crunched_data.iterrows():
    data[index] = {#'color': plt.cm.get_cmap('spring')(row.values[0]), 
                   'color': '#000000',
                   'percent': int(row.values[0]*100),
                   'deviation': abs(50 - int(row.values[0]*100))}

from circlegraph import make_figure
filename = make_figure(data, week=week, year=year, font="Latin Modern Mono")

twitter_handles = {'dn.se': '@Dagensnyheter', 'expressen.se': '@Expressen',
                   'svd.se': '@SvD', 'etc.se': '@ETC_redaktionen',
                   'svt.se': '@SVT', 'aftonbladet.se': '@Aftonbladet'}

# Get best and worst
best = sorted(data.iteritems(), key=lambda e: e[1]['deviation'])[0][0]
best_percent = sorted(data.iteritems(), key=lambda e: e[1]['deviation'])[0][1]['percent']
worst = sorted(data.iteritems(), key=lambda e: e[1]['deviation'])[-1][0]
worst_percent = sorted(data.iteritems(), key=lambda e: e[1]['deviation'])[-1][1]['percent']

tweet_to_worst = 'Vecka {week} hade {worst} {worst_percent} % kvinnor i sina texter och var därmed sämst denna vecka. Bäst var {best} med {best_percent} %.'.format(week=week, worst=twitter_handles[worst], worst_percent=worst_percent, best=twitter_handles[best], best_percent=best_percent)
print tweet_to_worst
assert len(tweet_to_worst) < 140
Ejemplo n.º 3
0
# -*- coding: utf-8 -*-
import tweepy
import config as conf
import datetime

""" Make graph of the last month """

from crunch import crunch_data
crunched_data, week, year = crunch_data(weeks=10, on="month")
crunched_data = crunched_data.dropna(axis=0)
print crunched_data

data = {}
for index, row in crunched_data.iterrows():
    data[index] = {'color': '#000000',
                   'percent': int(row.values[-2]*100),
                   'deviation': abs(50 - int(row.values[-2]*100))}

monthnames = {1: 'Januari', 2: 'Februari', 3: 'Mars', 4: 'April',
              5: 'Maj', 6:'Juni', 7: 'Juli', 8: 'Augusti',
              9: 'September', 10: 'Oktober', 11: 'November',
              12: 'December'}

from circlegraph import make_figure
filename = make_figure(data, 
                       text=monthnames[crunched_data.columns[-2]], 
                       year=year, 
                       font="Latin Modern Mono",
                       filename="graphs/monthly.png")

print "Genereated file: {}".format(filename)