Created
October 3, 2018 21:57
-
-
Save numeroteca/3b67dc8aa92572e913527cf105938652 to your computer and use it in GitHub Desktop.
Twitter bot to post tweets based on existing csv DataEducation.bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zona | perc_bec_comedor_pub | perc_bec_comedor_priv | zona_id | total_alumnado | provincia | municipios_barrios | |
---|---|---|---|---|---|---|---|
Amurrio | 33 | 14 | 111 | 1467 | Araba | Aiara, Amurrio, Artziniega, Okondo, Orduña | |
Arrasate | 14 | 3 | 211 | 4423 | Gipuzkoa | Aramaio, Aretxabaleta, Arrasate, Eskoriatza, Oñate | |
Bermeo | 31 | 30 | 311 | 1772 | Bizkaia | Bermeo, Mundaka | |
Urdaibai | 22 | 22 | 312 | 2412 | Bizkaia | Arratzu, Busturia, Gautegiz, Gernika, Muxika | |
Bergara | 18 | 3 | 212 | 2053 | Gipuzkoa | Antzuola, Bergara, Elgeta, Soraluze | |
Lea-Artibai | 18 | 20 | 321 | 2415 | Bizkaia | Amoroto, Aulesti, Berriatua, Etxebarria, Ispaster, Lekeitio, Markina, Munitibar, Ondarroa | |
Amorebieta | 30 | 9 | 331 | 2724 | Bizkaia | Amorebieta | |
Llodio | 26 | 15 | 112 | 1971 | Araba | Llodio, Orozko | |
Eibar | 29 | 7 | 221 | 2547 | Gipuzkoa | Eibar | |
Vitoria Oeste | 25 | 7 | 121 | 7032 | Araba | Gasteizk, Zigoitia, Zuia | |
Vitoria Norte | 31 | 6 | 122 | 5002 | Araba | Arrazua, Gasteiz | |
Durango | 22 | 12 | 332 | 6052 | Bizkaia | Abadiño, Atxondo, Berriz, Durango, Elorrio, Iurreta, Mallabia, Otxandio, Zaldibar | |
Ermua | 20 | 15 | 333 | 1313 | Bizkaia | Ermua | |
Igorre | 21 | 341 | 1184 | Bizkaia | Areatza, Artea, Dima, Igorre, Lemoa, Zeanuri, Zeberio | ||
Vitoria Sureste | 35 | 5 | 123 | 12489 | Araba | Alegria-Dulantzi, Gasteiz, Legutiano, Urkabustaiz | |
Elgoibar | 22 | 9 | 222 | 2394 | Gipuzkoa | Deba, Elgoibar, Mendaro, Mutriku | |
Montaña alavesa | 28 | 0 | 124 | 156 | Araba | Arraia-Maeztu, Kanpezu | |
Urola-Medio | 9 | 7 | 241 | 3266 | Gipuzkoa | Azkoitia, Azpeitia, Errezil, Zestoa | |
Kosta | 18 | 6 | 242 | 4843 | Gipuzkoa | Aia, Aizarnazabal, Getaria, Orio, Zarautz, Zestoa, Zumaia | |
Galdakao | 30 | 10 | 342 | 2169 | Bizkaia | Galdakao | |
Arrigorriaga | 24 | 21 | 351 | 1626 | Bizkaia | Arrankudiaga, Arrigorriaga, Orduña, Ugao, Zaratamo | |
Basauri | 33 | 16 | 352 | 3911 | Bizkaia | Basaur, Etxebarri | |
Araba occidental | 31 | 15 | 125 | 752 | Araba | Erribera Beitia, Iruña Oka, Valdegovia | |
Tolosa | 26 | 9 | 251 | 5212 | Gipuzkoa | Abaltzisketa, Aduna, Albiztur, Alegia, Alkiza, Altzo, Amezketa, Anoeta, Asteasu, Berastegi, Berrobi, Bidegoyan, Ibarra, Ikaztegieta, Irura, Lizartza, Tolosa, Villabona, Zizurkil | |
Hernani | 24 | 65 | 261 | 2226 | Gipuzkoa | Hernani, Urnieta | |
Lasartealdea | 15 | 3 | 262 | 1862 | Gipuzkoa | Lasarte-Oria, Usurbil | |
Rioja alavesa | 35 | 20 | 131 | 1236 | Araba | Elciego, Labastida, Laguardia, Lantziego, Lapuebla, Mañueta, Oion | |
Andoain | 53 | 9 | 263 | 1850 | Gipuzkoa | Andoain, Urnieta | |
Donostia Margen izq | 27 | 8 | 271 | 11265 | Gipuzkoa | Donostia | |
Donostia Margen dcha | 32 | 12 | 272 | 4506 | Gipuzkoa | Donostia | |
Encartaciones | 37 | 15 | 361 | 3064 | Bizkaia | Alonsotegi, Artzentales, Balmaseda, Gordexola, Güeñes, Karrantza, Sopuerta, Trucios, Zalla | |
Trapaga | 45 | 16 | 371 | 1880 | Bizkaia | Ortuella, Valle de Trapaga, | |
Abanto | 30 | 18 | 372 | 2019 | Bizkaia | Abanto y Ciérvena, Muskiz | |
Llanada oriental | 20 | 12 | 141 | 774 | Araba | Agurain, Asparrena | |
Donostia Este | 44 | 22 | 273 | 2856 | Gipuzkoa | Donostia, Pasaia | |
Renteria | 40 | 18 | 281 | 6475 | Gipuzkoa | Errenteria, Lezo, Oiartzun | |
Txorierri | 26 | 5 | 381 | 7831 | Bizkaia | Derio, Larrabetzu, Lezama, Loiu, Sondika, Zamudio | |
Mungia | 29 | 14 | 382 | 2317 | Bizkaia | Bakio, Gatika, Laukiz, Mungia | |
Uribe-Kosta | 34 | 9 | 393 | 10575 | Bizkaia | ||
Erandio | 27 | 15 | 394 | 2330 | Bizkaia | Erandio | |
Barakaldo | 45 | 13 | 411 | 1612 | Bizkaia | Barakaldo | |
Cruces | 39 | 12 | 412 | 5097 | Bizkaia | Barakaldo | |
Sestao | 48 | 18 | 421 | 3174 | Bizkaia | Sestao | |
Portugalete | 42 | 28 | 422 | 2042 | Bizkaia | Portugalete | |
Santurtzi | 37 | 14 | 423 | 4577 | Bizkaia | Santurtzi | |
Bidasoa | 34 | 15 | 291 | 7350 | Gipuzkoa | Hondarribia, Irun | |
Leioa-Getxo | 39 | 14 | 391-392 | 3567 | Bizkaia | Leioa, Getxo, Berango, Getxo, Leioa | |
Alto-Oria | 15 | 7 | 231 | 4694 | Gipuzkoa | Ataun, Beasain, Gabiria, Idiazabal, Itsasondo, Lazkao, Legorreta, Olaberria, Ordizia, Ormaiztegi, Segura, Zaldibia, Zegama, Zerain | |
Alto-Urola | 16 | 7 | 232 | 2524 | Gipuzkoa | Legazpi, Urretxu, Zumarraga | |
Deusto | 36 | 13 | 1 | 3719 | Bizkaia | Bilbao | |
Uribarri | 45 | 23 | 2 | 4156 | Bizkaia | Bilbao | |
Txurdinaga-Otxarkoaga | 61 | 23 | 3 | 3629 | Bizkaia | Bilbao | |
Begoña | 46 | 27 | 4 | 2517 | Bizkaia | Bilbao | |
Ibaiondo | 46 | 25 | 5 | 4530 | Bizkaia | Bilbao | |
Abando | 38 | 9 | 6 | 6054 | Bizkaia | Bilbao | |
Rekalde | 59 | 35 | 7 | 1744 | Bizkaia | Bilbao | |
Basurto-Zorroza | 55 | 0 | 8 | 829 | Bizkaia | Bilbao |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2.7 | |
# -*- 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 | |
config={} | |
execfile("TweetConfig.py", 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(): | |
# Open data file | |
filename = "data.csv" | |
with open(filename, 'r') as csvfile: | |
spamreader = csv.DictReader(csvfile) | |
# csv rows loop | |
for row in spamreader: | |
zona = row['zona'] | |
provincia = row['provincia'] | |
perc_bec_comedor_pub = row['perc_bec_comedor_pub'] | |
perc_bec_comedor_priv = row['perc_bec_comedor_priv'] | |
status_text = 'En la zona escolar de ' + zona + ' (' + provincia + ') hay ' + perc_bec_comedor_pub + '% de alumnado becado para comedor en la escuela pública vs ' + perc_bec_comedor_priv + '% en la concertada-privada. EAJ-PNV, PSE-EE y PPVasco no impidáis que se debata en Parlamento. Aceptad a trámite la ILP_EInklusiboa el jueves' | |
print (len(status_text)) | |
status = api.PostUpdate(status_text.decode("utf-8")) | |
time.sleep(303) | |
print(status_text) | |
# Schedule tweetExpense every minute | |
schedule.every(1).minutes.do(tweetExpense) | |
while True: | |
schedule.run_pending() | |
time.sleep(15) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-------------------------------------------------------------------------------- | |
# These tokens are needed for user authentication. | |
# Credentials can be generates via Twitter's Application Management: | |
# https://apps.twitter.com/app/new | |
# | |
# This file must be renamed as TweetConfig.py | |
# to make the script works | |
#-------------------------------------------------------------------------------- | |
consumer_key = "" | |
consumer_secret = "" | |
access_key = "" | |
access_secret = "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment