Skip to content

Instantly share code, notes, and snippets.

@fanzeyi
Created January 23, 2011 14:48
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 fanzeyi/792119 to your computer and use it in GitHub Desktop.
Save fanzeyi/792119 to your computer and use it in GitHub Desktop.
饭否话唠刷屏器= =
#!/usr/bin/python
#coding=UTF-8
'''Fanfou Hualao Bash'''
import sys
from os import system
AT = None
TOPIC = None
def Send_Message(msg):
'''Send Fanfou Message'''
if AT != None:
msg = "@" + AT + " " + msg
if TOPIC != None:
msg = msg + " #" + TOPIC + "#"
system("fanfou " + msg)
return 1
def handle_cmd(cmd):
'''Handle Inputs'''
global AT
global TOPIC
if cmd == 'exit':
return 0
AcceptArgv = ['at', 'topic']
AcceptCmds = ['set', 'print', 'clear']
if len(cmd.split()) == 0:
return 1
if cmd.split()[0] not in AcceptCmds:
return Send_Message(cmd)
if cmd[:3] == 'set':
cmd = cmd[4:]
if len( cmd.split() ) != 2:
print 'Input Error!'
return 1
try:
name, value = cmd.split()
except ValueError:
print 'Input Error!'
else:
name = name.lower()
if name not in AcceptArgv:
print 'Input Error!'
elif name == 'at':
AT = value
elif name == 'topic':
TOPIC = value
print "Success Set Global Variable!"
if cmd[:5] == 'clear':
cmd = cmd[6:]
if len( cmd.split() ) != 1:
print 'Input Error!'
return 1
try:
name = cmd.split()[0]
except ValueError:
print 'Input Error!'
else:
name = name.lower()
if name not in AcceptArgv:
print 'Input Error!'
elif name == 'at':
AT = None
elif name == 'topic':
TOPIC = None
print "Success Clear Global Variable!"
if cmd[:5] == 'print':
cmd = cmd[6:]
if len( cmd.split() ) != 1:
if AT != None:
print "At : " + AT
if TOPIC != None:
print "Topic : " + TOPIC
return 1
try:
name = cmd.split()[0]
except ValueError:
if AT != None:
print "At : " + AT
if TOPIC != None:
print "Topic : " + TOPIC
else:
name = name.lower()
if name not in AcceptArgv:
if AT != None:
print "At : " + AT
if TOPIC != None:
print "Topic : " + TOPIC
elif name == 'at':
if AT != None:
print "At : " + AT
else:
print "None"
elif name == 'topic':
if TOPIC != None:
print "Topic : " + TOPIC
else:
print "None"
return 1
def main():
'''Main Function'''
j = 1
banner = '''Welcome To Fanfou Hualao Message Sender!
Current Version 0.0.1 Alpha
Based On Seviper Author: Zeray Fan'''
print banner
while j:
sys.stdout.write('Fanfou > ')
try:
Command = raw_input()
except EOFError:
sys.stdout.write('\nBye~\n')
Command = 'exit'
except KeyboardInterrupt:
sys.stdout.write('\nBye~\n')
Command = 'exit'
j = handle_cmd(Command)
return 0
if __name__ == '__main__':
exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment