cdleong commited on
Commit
92a84ae
1 Parent(s): add10f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import streamlit as st
2
  import langcodes
3
 
 
4
  # https://huggingface.co/blog/streamlit-spaces
5
  langtext = st.text_input("language lookup using https://github.com/rspeer/langcodes, see also https://r12a.github.io/app-subtags/", "english")
6
 
@@ -36,6 +37,22 @@ if lang is None:
36
  lang = None
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
 
41
  #st.write(f"langcodes found the following tag: {type(found)}") # a Language object
@@ -53,6 +70,13 @@ if lang is not None:
53
  st.write(f"If it exists, the ISO 639 Code Tables entry for the T variant would be at https://iso639-3.sil.org/code/{t_variant}")
54
  st.write(f"If it exists, the ISO 639 Code Tables entry for the B variant would be at https://iso639-3.sil.org/code/{b_variant}")
55
 
 
 
 
 
 
 
 
56
 
57
  broader_tags = lang.broader_tags()
58
  st.write(f"Broader tags for this language, if any: {broader_tags}")
1
  import streamlit as st
2
  import langcodes
3
 
4
+
5
  # https://huggingface.co/blog/streamlit-spaces
6
  langtext = st.text_input("language lookup using https://github.com/rspeer/langcodes, see also https://r12a.github.io/app-subtags/", "english")
7
 
37
  lang = None
38
 
39
 
40
+ def pull_obsolete_codes(iso_code):
41
+ from requests_html import HTMLSession
42
+ session = HTMLSession()
43
+ r= session.get(f"https://iso639-3.sil.org/code/{iso_code}")
44
+ for thing in r.html.find(".views-field-nothing", clean=True):
45
+ lines = thing.text.splitlines()
46
+ # lines = text.splitlines()
47
+ obsolete_codes = {}
48
+ for line in lines:
49
+ for obsolete_code_name in ["639-1","639-2/B", "639-2/T", "639-3"]
50
+ if obsolete_code_name in line:
51
+ print(line)
52
+ code = line.split()[-1]
53
+ print(code)
54
+ obsolete_codes[obsolete_code_name] = code
55
+ return obsolete_codes
56
 
57
 
58
  #st.write(f"langcodes found the following tag: {type(found)}") # a Language object
70
  st.write(f"If it exists, the ISO 639 Code Tables entry for the T variant would be at https://iso639-3.sil.org/code/{t_variant}")
71
  st.write(f"If it exists, the ISO 639 Code Tables entry for the B variant would be at https://iso639-3.sil.org/code/{b_variant}")
72
 
73
+
74
+ # ethnologue prefers T for german (deu), and T for French
75
+ obsolete_codes = pull_obsolete_codes(t_variant)
76
+
77
+
78
+
79
+
80
 
81
  broader_tags = lang.broader_tags()
82
  st.write(f"Broader tags for this language, if any: {broader_tags}")