#!/usr/bin/env python3 import requests,html.parser;r=requests.get("https://tilde.tel/phonebook.html").content.decode("utf-8"); class h(html.parser.HTMLParser): d=False def handle_starttag(self, tag, attrs): self.d=True if (tag=="pre") else False; def handle_data(self, data): if (self.d==True and data.strip() != ""): self.data=data h=h();h.feed(r); sections=["Service Numbers","The 1900s","~Tel Community"] # ^↑^ probably a bit easier to update when needed (when the update miraculously doesn't break the rest) def print_services(nr,name,tilde,rest): name=" ".join([name,rest]) #custom name override, I think it just looks better if (nr=="1102"): name="Music on Hold (tilderadio)" print("|",nr,"|",name); def print_1900s(nr,name,tilde,rest): #fix for the sdf gateway description if (nr=="1987"): rest=rest.split("(")[0] print("|",nr,"|",rest,"(by",name+")"); def print_users(nr,name,tilde): print("|",nr,"|",name.rjust(18),("("+tilde+")").ljust(0)); for i in h.data.split("\n"): i=i.split();global x; if (i != [] and not i[0].startswith("[")): if(" ".join(i) in sections): section=" ".join(i); print("\nSection:",section,"\n"); c=True; else: c=False; if (i[0].isdigit() == False): tilde=i.pop(0); if c: tilde="" nr=i.pop(0); if (nr.isdigit() == False): tilde="";continue name=rest="";j=0 if(c!=True): for n in i: j+=1 if j==1:name=n else: rest=rest+n+" "; name=name.strip(); if (section==sections[0]): print_services(nr,name,tilde,rest); if (section==sections[1]): print_1900s(nr,name,tilde,rest); if (section==sections[2]): print_users(nr,name,tilde);