added the scripts

This commit is contained in:
jan6 2020-09-23 22:33:32 +03:00
parent 8dad651879
commit 26c4a87c6d
3 changed files with 57 additions and 2 deletions

View File

@ -1,3 +1,7 @@
# tildetel
# tildetel stuff
some stuff for tilde.tel, such as a phonebook scraper, and a microsip contact list making scraper
some stuff for tilde.tel, such as a phonebook scraper, and a microsip contact list making scraper
* scrapbook.py - python script that generates a pretty OK display of the contacts list, should be trivial to turn to CSV
* microsip_contactlist.sh - uses standard shell utilities to mangle and straighten the contact list into MicroSIP's contacts CSV file,
outputs tilde.tel.users.csv in the current directory

1
microsip_contactlist.sh Executable file
View File

@ -0,0 +1 @@
printf "\357\273\277%s\n" "Name,Number,Presence,Directory" >tilde.tel.users.csv;{ curl https://tilde.tel/phonebook.html|grep -A 9999 "\[Tilde\]"|grep -B 9999 "</pre>"|tail -n +1|head -n -1|grep -v "<\(\|/\)pre>"|tr -s "[:blank:]" "\t"|while read i;do [ -n "$i" ]&&{ echo "$i"|grep -s "^[^.]*\.[^.]*";}&&{ realm="$(echo "$i"|cut -f 1)";rest="$(echo "$i"|cut -f 2-)";}||rest="$i";[ -n "$rest" ]&&echo "$realm $rest";done|tr -s "[:blank:]" "\t"|uniq|sort|awk -F "\t" '{print $3" ("$1"),"$2",1,0"}';} >>tilde.tel.users.csv

50
scrapbook.py Executable file
View File

@ -0,0 +1,50 @@
#!/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);