Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Created November 4, 2014 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZiTAL/c259727f9702d4d2cf11 to your computer and use it in GitHub Desktop.
Save ZiTAL/c259727f9702d4d2cf11 to your computer and use it in GitHub Desktop.
#zitalbot python twitter bot
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# requirements:
# pip install tweepy
import sys, re, tweepy
class Txio(object):
params = {}
api = {}
def __init__(self):
self.getArg()
self.setApi()
self.tweet()
def getArg(self):
lastKey = ''
j = 0
tmp = {}
for i in sys.argv:
if(re.match("^\-\-", i)):
lastKey = i
tmp[lastKey] = ''
j = 0
else:
if(lastKey!=''):
if(j>0):
tmp[lastKey] = tmp[lastKey]+" "
tmp[lastKey] = tmp[lastKey]+i
j = j+1
self.params = tmp
def setApi(self):
auth = tweepy.OAuthHandler(self.params['--consumer-key'], self.params['--consumer-secret'])
auth.set_access_token(self.params['--access-token'], self.params['--access-secret'])
api = tweepy.API(auth)
self.api = api
def tweet(self):
self.api.update_status(self.params['--tweet'])
Txio()
sys.exit()
# garrantzitsua: https://apps.twitter.com/apps webgunean sortu aplikazio berri bat eta lortu key eta token denak
#
# erabilera:
#
# zitalbot.py \
# --consumer-key cOnSuMeRkEy12345 \
# --consumer-secret cOnSuMeRsEcReT12345 \
# --access-token aCcEsToKen12345 \
# --access-secret aCcEsSeCrEt12345 \
# --tweet WALKEN FOX 22:20 eta COSMOS National geographic 23:30 \@aitorp6 \@xanxanlatulipe \#zitalbot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment