python_examples
This is an old revision of the document!
Mystic Python Examples
This page contains examples of code using Mystic Python.
msgread.mpy
Python functions for reading Message Bases are:
msg_open, msg_seek, msg_found, msg_next, msg_prev, msg_gethdr, msg_gettxt, msg_close
This script is an example of how to use these functions. It implements a very basic message reader using the user's current message base.
##################################################### # Simple Message Reader Example using Mystic Python # ##################################################### # Reads messages in the user's current message base # With a pause prompt that allows quitting from mystic_bbs import * # Load the current user and then load their current message base # but fail if they have not selected a message base user = getuser(0) mbase = getmbaseid(user["mbase"]) if mbase is None: writeln ("|CRYou have not selected a message base yet!|CR|CR|PA") quit() # Open the message base then check to make sure its open before reading # data from it msg = msg_open(mbase["path"] + mbase["filename"]); if msg is None: quit() done = False # Seek to the first message in the base and loop while a message # is found, calling msg_next after each message so the next one # will be loaded. Seek must be called first even if reading # from the first message. msg_seek(msg, 0) while msg_found(msg) and not done and not shutdown(): # Load the message header information into a dictionary # and the message text into a list msghdr = msg_gethdr(msg) msgtext = msg_gettxt(msg) # Show the message header, setting a line counter that can # be used to pause the screen pausecount = 3 writeln("From: " + msghdr["from"]); writeln(" To: " + msghdr["to"]); writeln("Subj: " + msghdr["subj"]); writeln("-----"); # loop through each line in the message (list) and pause when # we get more than 23 lines for line in msgtext: pausecount += 1 writeln(line) if pausecount >= 23: pausecount = 1 write("*PAUSE* (ENTER) to continue, (Q) to Quit: ") if onekey(chr(13) + 'Q', True) == 'Q': done = True break # Load the next message msg_next(msg); # Close the message base and report that we're done msg_close(msg) writeln("|CRProgram complete.");
python_examples.1512461047.txt.gz · Last modified: 2017/12/05 02:04 by avon