autopep8
@@ -74,9 +74,9 @@ 'date': arrow.get(time).format(shared.ARROWFORMAT['iso']),
'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)@@ -855,6 +855,7 @@ img.meta = meta
img.pull_image() img.fix_extension() img.write_exif() + class TwitterFavs(Favs): url = 'https://api.twitter.com/1.1/favorites/list.json'
@@ -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 @@ atexit.register(
shutil.rmtree, os.path.abspath(self.tmp) ) - self.text = text; + self.text = text self.subject = subject self.images = [] self.ready = None@@ -102,14 +103,12 @@ if not isinstance(self.images, list):
self.images = [] self.images.append(i) - def __pull_images(self): mdmatch = re.compile( r'!\[.*\]\((.*?\.(?:jpe?g|png|gif)(?:\s+[\'\"]?.*?[\'\"]?)?)\)' r'(?:\{.*?\})?' ) [self.__pull_image(img) for img in mdmatch.findall(self.text)] - def __attach_images(self): self.__pull_images()@@ -118,18 +117,20 @@ cid = 'cid:%s' % (i['name'])
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')@@ -163,7 +164,6 @@ # --- HTML bit ---
# this is where it gets tricky: the HTML part should be a 'related' # 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 @@ s = smtplib.SMTP('127.0.0.1', 25)
# 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:
@@ -327,7 +327,6 @@ )
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 @@ fg.updated(arrow.get(self.mtime).to('utc').datetime)
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 @@
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(@@ -416,7 +415,6 @@ def render_paginated(self):
pagination = shared.config.getint('display', 'pagination') pages = ceil(len(self.data) / pagination) page = 1 - while page <= pages: add_welcome = False@@ -521,12 +519,16 @@ for target in self.urls_to_ping:
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:@@ -807,7 +809,6 @@ "height": self.photo.tmplvars.get('height'),
"url": self.photo.tmplvars.get('src'), }) return self._oembedvars - @property def tmplvars(self):@@ -874,14 +875,14 @@ logging.debug('writing file %s', o)
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 @@ mapping = {
'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 @@ if not author:
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 @@ if p.status_code == requests.codes.ok:
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 @@ return
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()@@ -1466,7 +1476,6 @@ with open(self.fpath, 'wt') as f:
logging.info("Saving webmention to %s", self.fpath) f.write(frontmatter.dumps(fm)) return - @property def relation(self):@@ -1600,14 +1609,13 @@ collector_front = Category(is_front=True)
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 @@ dtime = 0
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 @@ url: os.path.getmtime(s)
}) # 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 @@ @app.route("/oauth1", methods=["GET"])
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,