summaryrefslogtreecommitdiff
path: root/cli/app/thesaurus/api.py
diff options
context:
space:
mode:
Diffstat (limited to 'cli/app/thesaurus/api.py')
-rw-r--r--cli/app/thesaurus/api.py33
1 files changed, 24 insertions, 9 deletions
diff --git a/cli/app/thesaurus/api.py b/cli/app/thesaurus/api.py
index ad0dd92..98e0210 100644
--- a/cli/app/thesaurus/api.py
+++ b/cli/app/thesaurus/api.py
@@ -1,5 +1,6 @@
import os
import requests
+from hashlib import sha256
from app.utils.util import *
from app.settings import app_cfg
@@ -40,9 +41,23 @@ class ThesaurusAPI:
if resp.status_code != 200:
return []
data = resp.text
- data = data.split('<div id="resultsTimelineData">')
- data = data[0].split('</div>')
- return json.loads(data)
+ data = data.split('<div id="resultsTimelineData">')[1].split('</div>')[0]
+ # print(data)
+ rows = json.loads(data)
+ cats = []
+ for row in rows:
+ cat, years = row['popup'].split(']: ')
+ cat = cat.split('[')[1]
+ cats.append({
+ 'catid': row['catid'],
+ 'catnum': row['catnum'],
+ 'category': cat,
+ 'years': years,
+ })
+ return {
+ 'word': word,
+ 'categories': cats,
+ }
def category(self, id):
query = {
@@ -52,20 +67,20 @@ class ThesaurusAPI:
if resp.status_code != 200:
return ""
raw = resp.text
- classification = raw.split("<span style='font-size: 0.6em'>")[1].split('</span>')[0]
- category = raw.split("<br />")[1].split('</h2>')[0]
- raw_words = raw.split('<b>')[1:]
+ catnum = raw.split("<span style='font-size: 0.6em'>")[1].split('</span>')[0]
+ category = raw.split("<br />")[1].split('</h2>')[0].replace("<span style='font-size: 0.6em'>", "").replace("</span>", "")
+ raw_words = raw.split('"><b>')[1:]
words = []
for word in raw_words:
word, rest = word.split('</b>')
- years = word.split(' <span')[0].trim()
+ years = word.split(' <span')[0].strip()
words.append({
'word': word,
'years': years,
})
return {
- 'id': id,
+ 'catid': id,
+ 'catnum': catnum,
'category': category,
- 'classification': classification,
'words': words,
} \ No newline at end of file