Created
November 4, 2014 22:00
-
-
Save ZiTAL/c259727f9702d4d2cf11 to your computer and use it in GitHub Desktop.
#zitalbot python twitter 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
#!/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