Commit 0f5e57fd authored by Jean-Benoist Leger's avatar Jean-Benoist Leger

legifrance py3

parent 7dc89f1a
......@@ -35,7 +35,7 @@ def get_articles_from_page(link):
r = requests.get(link)
reg = '^.*?<a href="/?(affich[A-Za-z]*Article\.do[^"]*idArticle[^"]*)" title="En savoir plus sur l\'article ([^"]+)"'
c=r.content
c=r.content.decode()
while True:
a = re.match(reg, c, re.DOTALL)
......@@ -52,7 +52,7 @@ def get_articles_from_page(link):
def get_code(codename,codeids):
if not codeids.has_key(codename):
if not codename in codeids:
return None
codeid = codeids[codename]
......@@ -60,7 +60,7 @@ def get_code(codename,codeids):
r=requests.get('https://www.legifrance.gouv.fr/affichCode.do?cidTexte='+codeid)
reg = '^.*?href="(affichCode\.do[^"]*idSectionTA[^"]*)"'
c=r.content
c=r.content.decode()
links=set()
while True:
......@@ -80,7 +80,7 @@ def get_code(codename,codeids):
return articles
def get_text(textname, textids):
if not textids.has_key(textname):
if not textname in textids:
return None
textid = textids[textname]
......@@ -97,10 +97,10 @@ class legi:
t = time.time()
if self.cache.has_key(name):
if name in self.cache:
if t - self.cache[name]['timestamp'] > int(self.conf['expire']):
del self.cache[name]
if self.cache.has_key(name):
if name in self.cache:
pass
else:
if name in self.conf['codeids'].keys():
......@@ -111,13 +111,13 @@ class legi:
if not articles is None:
self.cache[name] = {'timestamp':t, 'articles':articles}
if self.cache.has_key(name):
if self.cache[name]['articles'].has_key(article):
if name in self.cache:
if article in self.cache[name]['articles']:
return self.cache[name]['articles'][article]
return None
def force_ct_reload(self,name):
if self.codes.has_key(name):
if name in self.codes:
self.codes[name]['timestamp']=0
return True
return False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment