10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-03 12:43:48 +01:00
QuantumPackage/scripts/utility/get_groups

73 lines
1.9 KiB
Plaintext
Raw Permalink Normal View History

2020-03-17 16:39:43 +01:00
#!/usr/bin/env python3
2019-01-25 11:39:31 +01:00
# -*- coding: utf-8 -*-
2020-03-17 16:39:43 +01:00
import urllib.request, urllib.parse, urllib.error
2019-01-25 11:39:31 +01:00
import sys
from bs4 import BeautifulSoup
address="http://gernot-katzers-spice-pages.com/character_tables/%s.html?fmt=simple"
def clean_up(text):
soup = BeautifulSoup(text, "lxml")
pre = soup.pre
group = pre.b.get_text()
sop = {}
irred = {}
irred_count = 0
sop_count = 0
for span in pre.find_all('span'):
cls = span.get('class')
if cls == ['sop']:
a = span.decode_contents()
if a not in sop:
sop[a] = sop_count
sop_count += 1
elif cls == ['irred']:
a = span.decode_contents()
if a not in irred:
irred[a] = irred_count
irred_count += 1
table = [ [] for j in sop ]
data = pre.get_text().splitlines()
def f(x):
y = x.split()
if len(y) == 0:
return False
else:
return y[0] in irred
2020-03-17 16:39:43 +01:00
data = list(filter(f,data))[:len(irred)]
2019-01-25 11:39:31 +01:00
for line in data:
s = line.replace('*','').split()
l = irred[s[0]]
2020-03-17 16:39:43 +01:00
data[l] = list(map(float,s[1:len(irred)+1]))
2019-01-25 11:39:31 +01:00
d = {}
e = {}
for k in irred:
d[irred[k]] = k
for k in sop:
e[sop[k]] = k
n = len(irred)
2020-03-17 16:39:43 +01:00
print("Group\t", group, "\nn\t", n)
print("\n \tIrred \tOperation")
2019-01-25 11:39:31 +01:00
for i in range(n):
2020-03-17 16:39:43 +01:00
print("%4d \t %s \t %s"%(i+1, d[i].ljust(10), e[i].ljust(10)))
2019-01-25 11:39:31 +01:00
2020-03-17 16:39:43 +01:00
print("\nTable\n ", end=' ')
2019-01-25 11:39:31 +01:00
for j in range(n):
2020-03-17 16:39:43 +01:00
print("%8s "%(str(j+1).center(8)), end=' ')
2019-01-25 11:39:31 +01:00
for i in range(n):
2020-03-17 16:39:43 +01:00
print("\n%4d "%(i+1), end=' ')
2019-01-25 11:39:31 +01:00
for j in range(n):
2020-03-17 16:39:43 +01:00
print("%8.5f "%(data[i][j]), end=' ')
print("\n")
2019-01-25 11:39:31 +01:00
def main():
for group in sys.argv[1:]:
2020-03-17 16:39:43 +01:00
f = urllib.request.urlopen(address%(group))
2019-01-25 11:39:31 +01:00
html = f.read().split('\n',1)[1]
text = clean_up(html)
if __name__ == "__main__":
main()