Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 61 lines (54 sloc) 2.08 KB
# -*- coding: utf-8 -*-
#Load required modules
import twitter
import csv
from datetime import datetime
#from time import sleep
import time
from dateutil.relativedelta import relativedelta
import schedule
# Twitter API configuration
execfile("", config)
# Twitter API authentication
api = twitter.Api(consumer_key=config['consumer_key'], consumer_secret=config['consumer_secret'], access_token_key=config['access_key'], access_token_secret=config['access_secret'])
# Tweet expense when correct time
def tweetExpense():
# date
now =
then = now - relativedelta(years=10)
then_date ="%Y-%m-%d")
then_time = then.time().strftime("%H:%M")
# Open data file
filename = "data/" +"%Y-%m") + "-data.csv"
with open(filename, 'r') as csvfile:
spamreader = csv.DictReader(csvfile)
# csv rows loop
for row in spamreader:
hora = row['hora'][:-3]
if then_date == row['date'] and then_time == hora:
#Checks if 'comercio' is empty ('NA' value)
if row['comercio'] == 'NA':
if row['operacion'] == 'REINTEGRO EN CAJERO PROPIO':
comercio = 'un cajero'
comercio = row['actividad'] #if comercio is not specified use the field "actividad"
comercio = row['comercio']
importe = row['importe']
quien = row['quien']
#Checks if is extracting money from the machine or spending in commerce to select one verb or another
if row['operacion'] == 'DISPOSICION EFECTIVO OFICINA' or row['operacion'] == 'REINTEGRO EN CAJERO PROPIO' or row['operacion'] == 'REINTEGRO EN CAJERO AJENO NACIONAL':
verbo = ' sacaba '
verbo = ' gastaba '
status_text = 'Hace 10 años ' + quien + verbo + importe + '€ con su tarjeta black en ' + comercio
#print (len(status_text))
status = api.PostUpdate(status_text)
# Schedule tweetExpense every minute
while True: