Beispiel #1
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
import tweepy
import config as conf

""" Used to take last weeks data, make a graph,
    and the post it to twitter 
"""

# Add credentials to config.example.py and rename to config.py
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'}
Beispiel #2
0
#!/usr/bin/python
# -*- 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")
Beispiel #3
0
# -*- coding: utf-8 -*-
import tweepy
import config as conf

""" Used to take last weeks data, make a graph,
    and the post it to twitter 
"""

# Add credentials to config.example.py and rename to config.py
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(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',
Beispiel #4
0
#!/usr/bin/python
# -*- coding: utf-8 -*- 
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib import cm
import pandas as pd
import sqlalchemy as sq
import numpy as np
import datetime

from crunch import crunch_data

print "Last couple of days"
print crunch_data(weeks=3, on="day")[0].T
print "---------------------------------------------------------------------------"


## Crunch by week

df_week, week, year = crunch_data(weeks=9, on="week", name_threshold=5)
df_week = df_week.T

# Colors
n_columns = len(df_week.columns)
colors = cm.Accent(np.linspace(0, 1, n_columns))

fig, ax = plt.subplots()

df_week.plot(ax=ax, legend=False, style='-o')
for line, color in zip(ax.lines, colors):