#! /usr/bin/env python3 import os import sys import urllib.request import http.client from html_table_parser import HTMLTableParser if ( len(sys.argv) == 2 and (sys.argv[1] == '-h' or sys.argv[1] == '--help' or sys.argv[1] == '-help') ): print('USAGE: P1: SessonID P2: VDC# [P3]: Line_Count') print(' optional: amount of lines to show <= 18') exit() if ( len(sys.argv) != 3 and len(sys.argv) !=4): raise ValueError('USAGE: P1: SessonID P2: VDC# [P3]: Line_Count') sid=sys.argv[1] vdc=sys.argv[2] if len(sys.argv) == 4: if (int(sys.argv[3]) > 18): lcs='18' else: lcs=sys.argv[3] else: lcs='18' url='https://XXXXXXXXXXX' + vdc + 'YYYYYYYYYYYYYY/ZZZZZZZZZZ/get?products=L1B_DATA__&recordFrom=0&recordTo=' + lcs + '&sortby=id&up=false' print("URL: ",url) print() #quit() headers = { 'Cookie': 'JSESSIONID='+sid, 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,*/*;q=0.8' } # get website content req = urllib.request.Request(url=url,headers=headers) f = urllib.request.urlopen(req) xhtml = f.read().decode('utf-8') # setup the html parser and feed it p = HTMLTableParser() p.feed(xhtml) table = p.tables[0][1:int(lcs)+1] maxlen = max(len(line[1]) for line in table) for i in range (1,maxlen+113): print("#",end ="") print() fmt2="#%-" + str(maxlen+110) + "s#" #print(fmt2 % (' VDC' + vdc)) print('#{0:^{w}}#'.format('VDC'+vdc,w=maxlen+110)) for i in range (1,maxlen+113): print("#",end ="") print() theader = p.tables[0][0] print('#{0:^7} | {1:{w}} | {2:9} | {3:^55} | {4:10} | Progress #'.format(*theader[0:5],w=maxlen)) for i in range (1,maxlen+113): print("#",end ="") print() for line in table: prgind=line[6].split() print('{0:>8} | {1:{w}} | {2:9} | {3:55} | {4:10} | {5:>4} {6:>4} {7:>4}'.format(*line[0:5],*prgind,w=maxlen))