Skip to content

Instantly share code, notes, and snippets.

@ZiTAL ZiTAL/zitalbot.py
Created Nov 4, 2014

Embed
What would you like to do?
#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
You can’t perform that action at this time.