_                _   _                 ____            _     _ 	
   / \   _ __   ___ | |_| |__   ___ _ __  |  _ \ _ __ ___ (_) __| |	
  / _ \ | '_ \ / _ \| __| '_ \ / _ \ '__| | | | | '__/ _ \| |/ _\` |	
 / ___ \| | | | (_) | |_| | | |  __/ |    | |_| | | | (_) | | (_| |	
/_/   \_\_| |_|\___/ \__|_| |_|\___|_|    |____/|_|  \___/|_|\__,_|	
                                                                bbs
  XQTRs lair...
Home // Blog // NULL emag. // Files // Docs // Tutors // GitHub repo
                                                                                
                                                                                
                                                                                
  i begun learning programming in python3, so as an exercise i made the         
  following functions to read the oneliners.dat and lastcaller.dat files.       
  it was a bitch to figure how to convert the pascal string format, cause       
  python likes to read everything as bytes, but at the end i managed to         
  make it. there is also a usefull function to unpack a DOS datetime value.     
  use the code in your own projects. i hate python, but i have to admit that    
  is something like a "universal language" in the computer tech. area. :(       
  for this reason, we should make more things with python in bbsing.            
                                                                                
                                                                                
--- rip here ----------------------------------------------------------------   
                                                                                
#!/usr/bin/python3                                                              
import struct                                                                   
import os                                                                       
from datetime import datetime                                                   
datadir = "/home/x/mysa43/data/"                                                
  # OneLineRec = Record                                                         
    # Text : String[79];                                                        
    # From : String[30];                                                        
  # End;                                                                        
def oneliners():                                                                
    f = open(datadir+"oneliner.dat","rb") # open the file                       
    sf = '@b79sb30s'                                                            
    s = struct.calcsize (sf)                                                    
    size = struct.calcsize(sf)                                                  
    print(size)  # size of record structure, just to know                       
    i = 0                                                                       
    d = 0                                                                       
    while True:                                                                 
        line = f.read(s) # read n bytes as the record size                      
        if len(line) < s:                                                       
            break                                                               
        i,onel,d,name = struct.unpack(sf,line)  # assign values to variables    
                                                                                
        # variable i contains the size of the oneliner text                     
        # variable d contains the size of the user name                         
        # we use the length to convert the vars onel and name to strings        
        # cause right now are byte arrays                                       
                                                                                
        print(''.join(str(name[0:d])).strip("b'"))  # print user name           
        print(''.join(str(onel[0:i])).strip("b'"))  # print text                
                                                                                
        print("---")                                                            
                                                                                
        line = ""                                                               
                                                                                
  # RecLastOn = Record    // CALLERS.DAT                                        
    # DateTime   : LongInt;                                                     
    # NewUser    : Boolean;                                                     
    # PeerIP     : String[15];                                                  
    # PeerHost   : String[50];                                                  
    # Node       : Byte;                                                        
    # CallNum    : LongInt;                                                     
    # Handle     : String[30];8-9                                               
    # City       : String[25];10-11                                             
    # Address    : String[30];12-13                                             
    # Gender     : Char;14                                                      
    # EmailAddr  : String[35];15-16                                             
    # UserInfo   : String[30];                                                  
    # OptionData : Array[1..10] of String[60];                                  
    # Reserved   : Array[1..53] of Byte;                                        
  # End;                                                                        
                                                                                
def unpackdt(t):                                                                
      year = 1980 + (t >> 25)                                                   
      month = (t & 0b00000001111000000000000000000000) >> 21                    
      day = (t & 0b00000000000111110000000000000000) >> 16                      
      hour = (t & 0b00000000000000001111100000000000) >> 11                     
      minute = (t & 0b00000000000000000000011111100000) >> 5                    
      second = (t & 0b00000000000000000000000000011111) * 2                     
      return datetime(year, month, day, hour, minute, second)                   
                                                                                
def lastcallers():                                                              
    f = open(datadir+"callers.dat","rb")                                        
    sf = '