Commit cc95aae7 authored by Stephen D's avatar Stephen D
Browse files

First commit. No wikipedia

parent 8f684989
import wolframalpha
import sys, fcntl, os
#Change these
wa_appid = "" #Wolfram app id
EOL = "\r"
pkt_len = 200
wa_client = None
connected = True
def chunkstring(string, length):
return (string[0+i:length+i] for i in range(0, len(string), length))
def print_ax(str): #Formats for ax25d
str += EOL
for chunk in chunkstring(str, pkt_len):
def help():
print_ax("Available commands:")
print_ax("ask <question>: Asks wolfram alpha (Uses internet. Do not rely on this in an emergency!)")
print_ax(" EX: ask Who is the prime minister of Canada")
print_ax("help: Display this message")
print_ax("bye: Disconnect from the host")
def ask(query): #Wolfram alpha
global wa_client
global wa_appid
if wa_client is None:
wa_client = wolframalpha.Client(wa_appid)
res = wa_client.query(query)
sys.stdout.write(next(res.results).text + EOL)
#Set input to be non-blocking
fd = sys.stdin.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
readbuf = ""
#Greet user
print_ax("Welcome to the VA1QLE packet radio assistant v0.1. You can query Wolfram Alpha and Wikipedia here.")
#Show commands
while connected:
readbuf +=
splitInput = readbuf.split(EOL)
if(len(splitInput) > 1): #Stuff to process
for text in splitInput[:-1]: #There may be multiple commands
splitted = text.split(' ', 1)
if splitted[0] == 'help':
elif splitted[0] == 'ask':
print_ax("Error connecting to wolfram alpha")
elif splitted[0] == 'bye':
print_ax("73 and Goodbye.")
connected = False
elif splitted[0] != '':
print_ax("ERROR: Command not found. Use 'help' to list available commands.")
readbuf = splitInput[-1] #Take what's left and put it back in the buffer
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment