Example #1
0
    def start_api(self):
		auth = tweepy.OAuthHandler(self.key, self.secret)
		config = ConfigInfo('config.ini')
		if not config.has_settings('Settings'):
			auth_url = auth.get_authorization_url()
			webbrowser.open(auth_url)
			print 'Please authorize: ' + auth_url
			verifier = raw_input('PIN: ').strip()
			auth.get_access_token(verifier)
			self.token_key, self.token_secret = auth.access_token.key, auth.access_token.secret
			config.add_settings('Settings')
			config.set_settings('Settings', 'token_key', self.token_key)
			config.set_settings('Settings', 'token_secret', self.token_secret)
		else:
			self.token_key = config.settings[0][1]
			self.token_secret = config.settings[1][1]
			
		auth.set_access_token(self.token_key, self.token_secret)
		self.api = tweepy.API(auth)
Example #2
0
#!/usr/bin/env python
import re, os
import subprocess
from read_config import ConfigInfo
from response import update_response

CMD_CHARS = ">>"
config = ConfigInfo('config.ini')

if config.keyword_exists('Settings', 'Chars'):
    CMD_CHARS = config.config.get('Settings', 'Chars')
    
CMD_PRECS = {CMD_CHARS + "shell(.*)": ""}
 
for key, value in config.commands:
	CMD_PRECS[CMD_CHARS + key + "(.*)"] = value
	

def cmd_exec(api, cmd, truncate):
	for key in CMD_PRECS:	
		matchObj = re.match(key, cmd)
		if matchObj:
			cmd = CMD_PRECS[key] + matchObj.group(1)
			cmd = cmd.split()
			try:
				resp = subprocess.check_output(cmd, shell = True, stderr = subprocess.STDOUT, universal_newlines = True)
			except CalledProcessError:
				resp = CalledProcessError.output
			if not resp: resp = "Success!"
			update_response(api, resp, truncate)
			return True