changeset 41:293a694304b8

reformat
author drewp@bigasterisk.com
date Sat, 19 Nov 2022 17:18:55 -0800
parents 94181d521d6d
children 530650b3bc40
files get_agent.py jadestache.py link.py lookup.py pagetitle.py
diffstat 5 files changed, 23 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/get_agent.py	Sat Nov 19 17:07:10 2022 -0800
+++ b/get_agent.py	Sat Nov 19 17:18:55 2022 -0800
@@ -13,10 +13,7 @@
     pomAssertion = bottle.request.headers.get('X-Pomerium-Jwt-Assertion', None)
 
     sk = jwks_client.get_signing_key_from_jwt(pomAssertion)
-    j = jwt.decode(pomAssertion,
-                   key=sk.key,
-                   algorithms=['ES256'],
-                   audience="bigasterisk.com")
+    j = jwt.decode(pomAssertion, key=sk.key, algorithms=['ES256'], audience="bigasterisk.com")
 
     foaf = {
         'drewpca@gmail.com': 'http://bigasterisk.com/foaf.rdf#drewp',
--- a/jadestache.py	Sat Nov 19 17:07:10 2022 -0800
+++ b/jadestache.py	Sat Nov 19 17:18:55 2022 -0800
@@ -8,6 +8,7 @@
     expands jade of incoming files. Also includes a cache so it doesn't
     read the same file twice
     """
+
     def __init__(self, *args, **kw):
         pystache.renderer.Loader.__init__(self, *args, **kw)
         self.seen = {}  # path : expanded jade
@@ -37,6 +38,7 @@
     Files need to end with .mustache since it's the mustache loader
     that's going to look for them.
     """
+
     def __init__(self, *args, **kw):
         debug = False
         if 'debug' in kw:
--- a/link.py	Sat Nov 19 17:07:10 2022 -0800
+++ b/link.py	Sat Nov 19 17:18:55 2022 -0800
@@ -1,7 +1,7 @@
+import urllib.error
 import urllib.parse
 import urllib.request
-import urllib.parse
-import urllib.error
+
 from dateutil.tz import tzlocal
 
 
@@ -10,6 +10,7 @@
 
 
 class Links(object):
+
     def __init__(self, db):
         self.coll = db['links']
 
@@ -53,8 +54,7 @@
 
         out['tagWords'] = [{'word': w} for w in out['tag'].split(None)]
         out['domain'] = urllib.parse.urlparse(out['href']).netloc
-        out['editLink'] = 'addLink?' + urllib.parse.urlencode(
-            [('url', out['href'])])
+        out['editLink'] = 'addLink?' + urllib.parse.urlencode([('url', out['href'])])
         out['shareWith'] = [{'label': uri} for uri in doc.get('shareWith', [])]
         return out
 
--- a/lookup.py	Sat Nov 19 17:07:10 2022 -0800
+++ b/lookup.py	Sat Nov 19 17:18:55 2022 -0800
@@ -17,17 +17,17 @@
 from collections import defaultdict
 
 import bottle
-import pymongo
 from bottle import static_file
 from dateutil.tz import tzlocal
 from prometheus_client.exposition import generate_latest
 from prometheus_client.registry import REGISTRY
 
+from get_agent import bottleGetAgent
 from jadestache import Renderer
 from link import Links, NotFound
+from mongo_required import die_on_mongo_connection_errors, open_mongo_or_die
 from pagetitle import PageTitle
-from mongo_required import open_mongo_or_die, die_on_mongo_connection_errors
-from get_agent import bottleGetAgent
+
 db = open_mongo_or_die()['href']
 pageTitle = PageTitle(db)
 links = Links(db)
@@ -35,6 +35,7 @@
 logging.basicConfig(level=logging.DEBUG)
 log = logging.getLogger()
 
+
 def getUser():
     try:
         agent = bottleGetAgent()
@@ -46,7 +47,7 @@
 
 def siteRoot():
     return 'https://bigasterisk.com/href'
-    
+
 
 @bottle.route('/static/<path:path>')
 def server_static(path):
@@ -170,7 +171,7 @@
 
 @bottle.route('/<user>', method='POST')
 def userAddLink(user):
-    u=getUser()[0]
+    u = getUser()[0]
     if u is None:
         raise ValueError('not logged in')
     if u != user:
--- a/pagetitle.py	Sat Nov 19 17:07:10 2022 -0800
+++ b/pagetitle.py	Sat Nov 19 17:18:55 2022 -0800
@@ -1,8 +1,9 @@
+import datetime
+import traceback
+
 import lxml.html.soupparser
-import datetime
+import requests
 from dateutil.tz import tzlocal
-import requests
-import traceback
 
 
 class CantGetTitle(ValueError):
@@ -10,18 +11,16 @@
 
 
 class PageTitle(object):
+
     def __init__(self, db):
         self.coll = db['pageTitle']
 
     def getPageTitleNow(self, uri):
         try:
-            response = requests.get(
-                uri,
-                timeout=3,
-                allow_redirects=True,
-                headers={
-                    'user-agent': 'link title checker - drewp@bigasterisk.com'
-                })
+            response = requests.get(uri,
+                                    timeout=3,
+                                    allow_redirects=True,
+                                    headers={'user-agent': 'link title checker - drewp@bigasterisk.com'})
             if not str(response.status_code).startswith('2'):
                 raise CantGetTitle("(got %s)" % response.status_code)
             root = lxml.html.soupparser.fromstring(response.text)
@@ -40,10 +39,6 @@
                 title = self.getPageTitleNow(uri)
             except CantGetTitle as e:
                 return str(e)
-            doc = {
-                '_id': uri,
-                'title': title,
-                'getTime': datetime.datetime.now(tzlocal())
-            }
+            doc = {'_id': uri, 'title': title, 'getTime': datetime.datetime.now(tzlocal())}
             self.coll.insert(doc)
         return doc['title']