autopep8
This commit is contained in:
parent
ce9ddb451a
commit
7ea5788388
5 changed files with 62 additions and 42 deletions
|
@ -74,9 +74,9 @@ class LastFM(object):
|
|||
'artist': data.get('artist').get('#text'),
|
||||
'album': data.get('album').get('#text'),
|
||||
'title': data.get('name')
|
||||
#'title_mbid': data.get('mbid'),
|
||||
#'artist_mbid': data.get('artist').get('mbid'),
|
||||
#'album_mbid': data.get('album').get('mbid'),
|
||||
# 'title_mbid': data.get('mbid'),
|
||||
# 'artist_mbid': data.get('artist').get('mbid'),
|
||||
# 'album_mbid': data.get('album').get('mbid'),
|
||||
}
|
||||
return (time, r)
|
||||
|
||||
|
@ -856,6 +856,7 @@ class TwitterFav(object):
|
|||
img.fix_extension()
|
||||
img.write_exif()
|
||||
|
||||
|
||||
class TwitterFavs(Favs):
|
||||
url = 'https://api.twitter.com/1.1/favorites/list.json'
|
||||
|
||||
|
|
17
envelope.py
17
envelope.py
|
@ -55,6 +55,7 @@ import smtplib
|
|||
import logging
|
||||
from shared import Pandoc
|
||||
|
||||
|
||||
class Letter(object):
|
||||
def __init__(self, sender=None, recipient=None, subject='', text=''):
|
||||
self.sender = sender or (getpass.getuser(), socket.gethostname())
|
||||
|
@ -68,7 +69,7 @@ class Letter(object):
|
|||
shutil.rmtree,
|
||||
os.path.abspath(self.tmp)
|
||||
)
|
||||
self.text = text;
|
||||
self.text = text
|
||||
self.subject = subject
|
||||
self.images = []
|
||||
self.ready = None
|
||||
|
@ -102,7 +103,6 @@ class Letter(object):
|
|||
self.images = []
|
||||
self.images.append(i)
|
||||
|
||||
|
||||
def __pull_images(self):
|
||||
mdmatch = re.compile(
|
||||
r'!\[.*\]\((.*?\.(?:jpe?g|png|gif)(?:\s+[\'\"]?.*?[\'\"]?)?)\)'
|
||||
|
@ -110,7 +110,6 @@ class Letter(object):
|
|||
)
|
||||
[self.__pull_image(img) for img in mdmatch.findall(self.text)]
|
||||
|
||||
|
||||
def __attach_images(self):
|
||||
self.__pull_images()
|
||||
for i in self.images:
|
||||
|
@ -118,18 +117,20 @@ class Letter(object):
|
|||
logging.debug("replacing %s with %s", i['url'], cid)
|
||||
self.text = self.text.replace(i['url'], cid)
|
||||
|
||||
|
||||
def make(self, inline_images=True):
|
||||
if inline_images:
|
||||
self.__attach_images()
|
||||
|
||||
|
||||
# Python, by default, encodes utf-8 in base64, which makes plain text
|
||||
# mail painful; this overrides and forces Quoted Printable.
|
||||
# Quoted Printable is still awful, but better, and we're going to
|
||||
# force the mail to be 8bit encoded.
|
||||
# Note: enforcing 8bit breaks compatibility with ancient mail clients.
|
||||
email.charset.add_charset('utf-8', email.charset.QP, email.charset.QP, 'utf-8')
|
||||
email.charset.add_charset(
|
||||
'utf-8',
|
||||
email.charset.QP,
|
||||
email.charset.QP,
|
||||
'utf-8')
|
||||
|
||||
mail = MIMEMultipart('alternative')
|
||||
|
||||
|
@ -164,7 +165,6 @@ class Letter(object):
|
|||
# wrapper, in which the text and all the related images are sitting
|
||||
_envelope = MIMEMultipart('related')
|
||||
|
||||
|
||||
html = self._tmpl
|
||||
_html = MIMEText(html, 'html', _charset='utf-8')
|
||||
# ---
|
||||
|
@ -218,7 +218,8 @@ class Letter(object):
|
|||
# unless you do the encode, you'll get:
|
||||
# File "/usr/local/lib/python3.5/smtplib.py", line 850, in sendmail
|
||||
# msg = _fix_eols(msg).encode('ascii')
|
||||
# UnicodeEncodeError: 'ascii' codec can't encode character '\xa0' in position 1073: ordinal not in range(128)
|
||||
# UnicodeEncodeError: 'ascii' codec can't encode character '\xa0'
|
||||
# in position 1073: ordinal not in range(128)
|
||||
s.sendmail(self.headers['From'], self.headers['To'], self.ready)
|
||||
s.quit()
|
||||
except Exception as e:
|
||||
|
|
67
nasg.py
67
nasg.py
|
@ -327,7 +327,6 @@ class Category(NoDupeContainer):
|
|||
r = shared.j2.get_template(tmplfile).render(tmplvars)
|
||||
self.write_html(o, r)
|
||||
|
||||
|
||||
def render_feed(self):
|
||||
start = 0
|
||||
end = int(shared.config.getint('display', 'pagination'))
|
||||
|
@ -367,7 +366,7 @@ class Category(NoDupeContainer):
|
|||
|
||||
for p in reversed(posttmpls):
|
||||
link = '%s/%s/' % (shared.site.get('url'), p.get('slug'))
|
||||
dt = arrow.get(p.get('pubtime')).to('utc')
|
||||
dt = arrow.get(p.get('pubtime')).to('utc')
|
||||
|
||||
content = p.get('html')
|
||||
if p.get('photo'):
|
||||
|
@ -399,8 +398,8 @@ class Category(NoDupeContainer):
|
|||
with open(o, 'wb') as f:
|
||||
f.write(fg.atom_str(pretty=True))
|
||||
|
||||
#with open(o.replace('.xml', '.rss'), 'wb') as f:
|
||||
#f.write(fg.rss_str(pretty=True))
|
||||
# with open(o.replace('.xml', '.rss'), 'wb') as f:
|
||||
# f.write(fg.rss_str(pretty=True))
|
||||
|
||||
# ping pubsub
|
||||
r = requests.post(
|
||||
|
@ -417,7 +416,6 @@ class Category(NoDupeContainer):
|
|||
pages = ceil(len(self.data) / pagination)
|
||||
page = 1
|
||||
|
||||
|
||||
while page <= pages:
|
||||
add_welcome = False
|
||||
if (self.is_front and page == 1):
|
||||
|
@ -521,12 +519,16 @@ class Singular(object):
|
|||
if not wdb.exists(self.url, target, self.published):
|
||||
wdb.queue(self.url, target)
|
||||
else:
|
||||
logging.debug("not queueing - webmention already queued from %s to %s", self.url, target)
|
||||
logging.debug(
|
||||
"not queueing - webmention already queued from %s to %s",
|
||||
self.url,
|
||||
target)
|
||||
wdb.finish()
|
||||
|
||||
@property
|
||||
def urls_to_ping(self):
|
||||
urls = [x.strip() for x in shared.REGEX.get('urls').findall(self.content)]
|
||||
urls = [x.strip()
|
||||
for x in shared.REGEX.get('urls').findall(self.content)]
|
||||
if self.is_reply:
|
||||
urls.append(self.is_reply)
|
||||
for url in self.syndicate:
|
||||
|
@ -808,7 +810,6 @@ class Singular(object):
|
|||
})
|
||||
return self._oembedvars
|
||||
|
||||
|
||||
@property
|
||||
def tmplvars(self):
|
||||
# very simple caching because we might use this 4 times:
|
||||
|
@ -874,14 +875,14 @@ class Singular(object):
|
|||
out.write(r)
|
||||
# use the comment time, not the source file time for this
|
||||
os.utime(o, (self.stime, self.stime))
|
||||
#oembed = os.path.join(
|
||||
#shared.config.get('common', 'build'),
|
||||
#self.fname,
|
||||
#'oembed.json'
|
||||
#)
|
||||
#with open(oembed, 'wt') as out:
|
||||
#logging.debug('writing oembed file %s', oembed)
|
||||
#out.write(json.dumps(self.oembedvars))
|
||||
# oembed = os.path.join(
|
||||
#shared.config.get('common', 'build'),
|
||||
# self.fname,
|
||||
# 'oembed.json'
|
||||
# )
|
||||
# with open(oembed, 'wt') as out:
|
||||
#logging.debug('writing oembed file %s', oembed)
|
||||
# out.write(json.dumps(self.oembedvars))
|
||||
|
||||
def __repr__(self):
|
||||
return "%s/%s" % (self.category, self.fname)
|
||||
|
@ -1013,7 +1014,7 @@ class WebImage(object):
|
|||
'camera': ['Model'],
|
||||
'aperture': ['FNumber', 'Aperture'],
|
||||
'shutter_speed': ['ExposureTime'],
|
||||
#'focallength': ['FocalLengthIn35mmFormat', 'FocalLength'],
|
||||
# 'focallength': ['FocalLengthIn35mmFormat', 'FocalLength'],
|
||||
'focallength': ['FocalLength'],
|
||||
'iso': ['ISO'],
|
||||
'lens': ['LensID', 'LensSpec', 'Lens'],
|
||||
|
@ -1335,9 +1336,10 @@ class Comment(object):
|
|||
return r
|
||||
|
||||
if 'name' in author:
|
||||
r.update({ 'name': self.meta.get('author').get('name')})
|
||||
r.update({'name': self.meta.get('author').get('name')})
|
||||
elif 'url' in author:
|
||||
r.update({ 'name': urlparse(self.meta.get('author').get('url')).hostname})
|
||||
r.update(
|
||||
{'name': urlparse(self.meta.get('author').get('url')).hostname})
|
||||
|
||||
return r
|
||||
|
||||
|
@ -1424,10 +1426,16 @@ class Webmention(object):
|
|||
logging.info("webmention sent")
|
||||
return True
|
||||
elif p.status_code == 400 and 'brid.gy' in self.target:
|
||||
logging.warning("potential bridgy duplicate: %s %s", p.status_code, p.text)
|
||||
logging.warning(
|
||||
"potential bridgy duplicate: %s %s",
|
||||
p.status_code,
|
||||
p.text)
|
||||
return True
|
||||
else:
|
||||
logging.error("webmention failure: %s %s", p.status_code, p.text)
|
||||
logging.error(
|
||||
"webmention failure: %s %s",
|
||||
p.status_code,
|
||||
p.text)
|
||||
return False
|
||||
except Exception as e:
|
||||
logging.error("sending webmention failed: %s", e)
|
||||
|
@ -1448,7 +1456,9 @@ class Webmention(object):
|
|||
|
||||
self._source = shared.XRay(self.source).parse()
|
||||
if 'data' not in self._source:
|
||||
logging.error("no data found in webmention source: %s", self.source)
|
||||
logging.error(
|
||||
"no data found in webmention source: %s",
|
||||
self.source)
|
||||
return
|
||||
self._save()
|
||||
|
||||
|
@ -1467,7 +1477,6 @@ class Webmention(object):
|
|||
f.write(frontmatter.dumps(fm))
|
||||
return
|
||||
|
||||
|
||||
@property
|
||||
def relation(self):
|
||||
r = 'webmention'
|
||||
|
@ -1600,14 +1609,13 @@ def build():
|
|||
collector_categories = NoDupeContainer()
|
||||
sitemap = {}
|
||||
|
||||
|
||||
for f, post in content:
|
||||
logging.info("PARSING %s", f)
|
||||
post.init_extras()
|
||||
post.queue_webmentions()
|
||||
|
||||
# add to sitemap
|
||||
sitemap.update({ post.url: post.mtime })
|
||||
sitemap.update({post.url: post.mtime})
|
||||
|
||||
# extend redirects
|
||||
for r in post.redirects:
|
||||
|
@ -1695,7 +1703,8 @@ def build():
|
|||
if os.path.exists(d):
|
||||
dtime = os.path.getmtime(d)
|
||||
|
||||
if not os.path.exists(d) or shared.config.getboolean('params', 'force') or dtime < stime:
|
||||
if not os.path.exists(d) or shared.config.getboolean(
|
||||
'params', 'force') or dtime < stime:
|
||||
logging.debug("copying static file %s to %s", s, d)
|
||||
shutil.copy2(s, d)
|
||||
if '.html' in item:
|
||||
|
@ -1705,7 +1714,11 @@ def build():
|
|||
})
|
||||
|
||||
# dump sitemap, if needed
|
||||
sitemapf = os.path.join(shared.config.get('common', 'build'), 'sitemap.txt')
|
||||
sitemapf = os.path.join(
|
||||
shared.config.get(
|
||||
'common',
|
||||
'build'),
|
||||
'sitemap.txt')
|
||||
sitemap_update = True
|
||||
if os.path.exists(sitemapf):
|
||||
if int(max(sitemap.values())) <= int(os.path.getmtime(sitemapf)):
|
||||
|
|
|
@ -49,7 +49,10 @@ if __name__ == '__main__':
|
|||
async def oauth1(request):
|
||||
token = request.args.get('oauth_token')
|
||||
verifier = request.args.get('oauth_verifier')
|
||||
logging.info("incoming oauth request: token was %s ; verifier was %s", token, verifier)
|
||||
logging.info(
|
||||
"incoming oauth request: token was %s ; verifier was %s",
|
||||
token,
|
||||
verifier)
|
||||
tokendb = shared.TokenDB()
|
||||
tokendb.update_token(
|
||||
token,
|
||||
|
|
|
@ -44,6 +44,7 @@ from inspect import getsourcefile
|
|||
import sys
|
||||
import arrow
|
||||
|
||||
|
||||
class CMDLine(object):
|
||||
def __init__(self, executable):
|
||||
self.executable = self._which(executable)
|
||||
|
@ -462,7 +463,7 @@ class SearchDB(BaseDB):
|
|||
#fpath = glob.glob(maybe_fpath).pop()
|
||||
ret.get(category).update({
|
||||
r.get('id'): {
|
||||
#'fpath': fpath,
|
||||
# 'fpath': fpath,
|
||||
'url': r.get('url'),
|
||||
'title': r.get('title'),
|
||||
'txt': r.get('txt')
|
||||
|
@ -521,7 +522,7 @@ class WebmentionQueue(BaseDB):
|
|||
cursor = self.db.cursor()
|
||||
cursor.execute(
|
||||
'''SELECT id,timestamp FROM queue WHERE source=? AND target=? ORDER BY timestamp DESC LIMIT 1''',
|
||||
(source,target)
|
||||
(source, target)
|
||||
)
|
||||
|
||||
rows = cursor.fetchall()
|
||||
|
@ -617,7 +618,7 @@ def __expandconfig():
|
|||
allow_no_value=True
|
||||
)
|
||||
conffile = os.path.join(
|
||||
os.path.dirname(os.path.abspath(getsourcefile(lambda:0))),
|
||||
os.path.dirname(os.path.abspath(getsourcefile(lambda: 0))),
|
||||
'config.ini'
|
||||
)
|
||||
c.read(conffile)
|
||||
|
@ -683,6 +684,7 @@ def __setup_sitevars():
|
|||
SiteVars.update({'tips': tips})
|
||||
return SiteVars
|
||||
|
||||
|
||||
ARROWFORMAT = {
|
||||
'iso': 'YYYY-MM-DDTHH:mm:ssZ',
|
||||
'display': 'YYYY-MM-DD HH:mm',
|
||||
|
|
Loading…
Reference in a new issue