From 28e177059d2ef20cde39027efa8a3184350283fe Mon Sep 17 00:00:00 2001 From: Dorian Date: Fri, 24 Feb 2023 15:34:03 +0100 Subject: [PATCH] new function for header --- wikipage/__pycache__/page.cpython-38.pyc | Bin 679 -> 985 bytes wikipage/page.py | 28 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/wikipage/__pycache__/page.cpython-38.pyc b/wikipage/__pycache__/page.cpython-38.pyc index 6e1388abcb66d02d9d74a70334a8bdb323b50710..abfc0840faadb69fb34c3299b7d4c57d1af0e357 100644 GIT binary patch literal 985 zcmYjQ&2G~`5T04viQ^_vl~A>SxaSg|5ErPBC`fRKDixICOSR1|i4(^*yBiuRn*)?% zZ=5)_N1lVX@Rd{F0C9m?r=V`MGdr{Mv-!U9>rN*CTHPPNM!5^{(;C;8L&g)@`aTH( z0uzWpFyWj+grX@t(KyA33EYRCe@QVg7@<{Hi)w=1PigBZi2}~y0!q>XXH0bk>{GoG z3n*|KghRd^x^oNMg8w!O?;(`sQ#Sz#QlO(Yjm9U8ebQTxhBYR z{qQ)R#W^3#(29Qkp=!nYaMiv+UG*jjaDC>Z%UryNL4E3?i)xK-DkjqrvoTl8BW($- z;r>Pk1Ls)a1tJ($z-Q7Y0|QgX!f$Cjb4qs7E|_q)iIgFv_gygVEKmak`=flXfD8PD zZy;p{WKSEE>sjK@oFUOb@i1*peaiWYP&(9MgL*mBmhC2*r8|TNG&-g8(K&!smBO{- zGEnxp&wH$D5LMAILD zlkqFOa`wjl0l(nMS=7Xt%e)g*KLHmdEfX|$>i#}tDXN)g2HNa|57LXX8DsGHyup5Q1KqtLb?fd=?H z8brKnh9?NhBb;h6%<$m?o8Yrc0z93>I{Dg!H=qtAKyS^i`5*?nwXBCFXQ>qqfBKo*kAXl(SL~Lf4OE_SWsXfg@ZyU9je^)-nRS0@pRk|?6w;XtCdQ1r6)pFu`0n(<~mMv^@kejJGLkRH;`e0B8L_$ rU=cUb#1acPs8;5oBDRbHNpEbwvqDz`|D^&^q;b^ii*(K{&P@Fq$XjA$ diff --git a/wikipage/page.py b/wikipage/page.py index 9dc510f..1e9c046 100644 --- a/wikipage/page.py +++ b/wikipage/page.py @@ -1,14 +1,36 @@ import wikipedia -wikipedia.set_lang("en") - # wikipedia # ------------------------------------------------------------------------ -def get_wikipage(pagename): +def is_header(line): + # return a couple of header_text and header_level + # or return nothing if line is not a header + + line = line.strip() + + if line == '': + return + + i = 0 + while line[i] == '=' and line[-1-i] == '=': + i += 1 + + if i == 0: + return + + header_text = line[i:(-1-i)].strip() + header_level = i + return [header_text, header_level] + + +def get_wikipage(pagename, lang = "en"): # get wikipedia page content by name of the page + wikipedia.set_lang(lang) + print(pagename) + try: results = wikipedia.search(pagename, results=1, suggestion=False) try: