comparison lookup.py @ 33:b82432594778

skaffold config and other updates
author drewp@bigasterisk.com
date Sat, 21 Aug 2021 14:24:57 -0700
parents c23acc88324b
children c7b59377ab35
comparison
equal deleted inserted replaced
32:c23acc88324b 33:b82432594778
8 """ 8 """
9 from collections import defaultdict 9 from collections import defaultdict
10 import datetime 10 import datetime
11 import json 11 import json
12 import logging 12 import logging
13 import os
13 import time 14 import time
14 import urllib.error 15 import urllib.error
15 import urllib.parse 16 import urllib.parse
16 import urllib.request 17 import urllib.request
17 18
23 24
24 from jadestache import Renderer 25 from jadestache import Renderer
25 from link import Links, NotFound 26 from link import Links, NotFound
26 from pagetitle import PageTitle 27 from pagetitle import PageTitle
27 28
28 db = pymongo.Connection('mongodb.default.svc.cluster.local', 29 db = pymongo.MongoClient(os.environ['MONGODB_SERVICE_HOST'],
29 tz_aware=True)['href'] 30 tz_aware=True)['href']
30 pageTitle = PageTitle(db) 31 pageTitle = PageTitle(db)
31 links = Links(db) 32 links = Links(db)
32 renderer = Renderer(search_dirs=['template'], debug=bottle.DEBUG) 33 renderer = Renderer(search_dirs=['template'], debug=bottle.DEBUG)
33 log = logging.getLogger() 34 log = logging.getLogger()
34 35
70 def allTags(user, withTags=[]): 71 def allTags(user, withTags=[]):
71 """withTags limits results to other tags that have been used with 72 """withTags limits results to other tags that have been used with
72 those tags""" 73 those tags"""
73 withTags = set(withTags) 74 withTags = set(withTags)
74 count = defaultdict(lambda: 0) # tag : count 75 count = defaultdict(lambda: 0) # tag : count
75 for doc in db['links'].find({'user': user}, fields=['extracted.tags']): 76 for doc in db['links'].find({'user': user}, projection=['extracted.tags']):
76 docTags = set(doc.get('extracted', {}).get('tags', [])) 77 docTags = set(doc.get('extracted', {}).get('tags', []))
77 if withTags and not withTags.issubset(docTags): 78 if withTags and not withTags.issubset(docTags):
78 continue 79 continue
79 for t in docTags.difference(withTags): 80 for t in docTags.difference(withTags):
80 count[t] = count[t] + 1 81 count[t] = count[t] + 1
241 return renderWithTime('index.jade', data) 242 return renderWithTime('index.jade', data)
242 243
243 244
244 if __name__ == '__main__': 245 if __name__ == '__main__':
245 logging.basicConfig(level=logging.INFO) 246 logging.basicConfig(level=logging.INFO)
246 bottle.run(server='gunicorn', host='0.0.0.0', port=10002, workers=4) 247 bottle.run(server='gunicorn', host='0.0.0.0', port=10002, workers=1)