[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[www_shared] 03/03: formatting
From: |
gnunet |
Subject: |
[www_shared] 03/03: formatting |
Date: |
Fri, 07 May 2021 11:07:41 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository www_shared.
commit 99649d50f26737d3a038e2052d0007a61226c32b
Author: Florian Dold <florian@dold.me>
AuthorDate: Fri May 7 12:55:53 2021 +0200
formatting
---
mybabel.py | 10 +++++-----
textproc.py | 29 ++++++++++++++++++++---------
time.py | 6 +++++-
3 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/mybabel.py b/mybabel.py
index 50fa0c4..daeb262 100644
--- a/mybabel.py
+++ b/mybabel.py
@@ -1,5 +1,5 @@
-#! /usr/bin/python3
-#
+#!/usr/bin/env python3
+
# This code is in the public domain.
#
# This is a wrapper around 'pybabel' that sets our include path
@@ -7,7 +7,7 @@
# pybabel program as the first argument (must be a Python script!)
# and passes the other arguments to pybabel after setting our
# sys.path.
-#
+
import shutil
import sys
@@ -15,11 +15,11 @@ import sys
sys.path.insert(0, ".")
# Now, find the actual pybabel program in the $PATH
-pb=shutil.which(sys.argv[1])
+pb = shutil.which(sys.argv[1])
# Remove 'pybabel' from argv[] so that pybabel doesn't confuse
# itself for the first command-line argument ;-)
sys.argv.remove(sys.argv[1])
# Now we can run pybabel. Yeah!
-exec(compile(source=open(pb).read(), filename=pb, mode='exec'))
+exec(compile(source=open(pb).read(), filename=pb, mode="exec"))
diff --git a/textproc.py b/textproc.py
index 5a2f96d..e39ee12 100644
--- a/textproc.py
+++ b/textproc.py
@@ -29,7 +29,7 @@ class extractText(html.parser.HTMLParser):
self.result.append(data)
def text_in(self):
- return ''.join(self.result)
+ return "".join(self.result)
def html2text(html):
@@ -44,12 +44,12 @@ def cut_text(filename, count):
for script in soup(["script", "style"]):
script.extract()
k = []
- for i in soup.findAll('p')[1]:
+ for i in soup.findAll("p")[1]:
k.append(i)
- b = ''.join(str(e) for e in k)
+ b = "".join(str(e) for e in k)
text = html2text(b.replace("\n", ""))
- textreduced = (text[:count] + ' [...]') if len(text) > count else
(text)
- return (textreduced)
+ textreduced = (text[:count] + " [...]") if len(text) > count else
(text)
+ return textreduced
def cut_news_text(filename, count):
@@ -63,9 +63,9 @@ def cut_by_frontier(filename):
with open(filename) as html:
soup = BeautifulSoup(html, features="lxml")
k = []
- for i in soup.find(id='newspost-content'):
+ for i in soup.find(id="newspost-content"):
k.append(i)
- b = ''.join(str(e) in k)
+ b = "".join(str(e) in k)
text = b.replace("\n", "")
return text
@@ -73,11 +73,22 @@ def cut_by_frontier(filename):
def cut_article(filename, conf, lang):
return cut_all("template/news/" + filename + ".j2", conf, lang)
+
def cut_all(filename, conf, lang):
with open(filename) as html:
soup = BeautifulSoup(html, features="lxml")
- i = repr(soup).replace('{% extends "common/news.j2" %}\n{% block
body_content %}\n', "").replace('\n{% endblock body_content %}',
"").replace('<html><body><p></p>',"").replace('</body></html>', "")
+ i = (
+ repr(soup)
+ .replace('{% extends "common/news.j2" %}\n{% block body_content
%}\n', "")
+ .replace("\n{% endblock body_content %}", "")
+ .replace("<html><body><p></p>", "")
+ .replace("</body></html>", "")
+ )
urlstr = "https://" + conf["siteconf"]["baseurl"] + "/" + lang + "/"
- text = i.replace("\n", "").replace("{{ url_localized('",
urlstr).replace("') }}", "")
+ text = (
+ i.replace("\n", "")
+ .replace("{{ url_localized('", urlstr)
+ .replace("') }}", "")
+ )
# .replace('<', '<').replace('>', '>').replace('"', '"')
return text
diff --git a/time.py b/time.py
index bfd6a39..d023de7 100644
--- a/time.py
+++ b/time.py
@@ -20,9 +20,11 @@ import time
import datetime
import email.utils
+
def time_now():
return datetime.datetime.now(tz=datetime.timezone.utc)
+
def conv_date(t):
# naively assumes its input is always a Y-m-d.
if type(t) == str:
@@ -34,12 +36,14 @@ def conv_date(t):
else:
return sys.exit(1)
+
def conv_date_rfc822(t):
return time_rfc822(conv_date(t))
+
def time_rfc822(t):
if type(t) == float:
return email.utils.formatdate(t)
elif type(t) == datetime.datetime:
- return email.utils.format_datetime(t,usegmt=True)
+ return email.utils.format_datetime(t, usegmt=True)
raise TypeError()
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.