Compare commits

1 Commits
Author SHA1 Message Date
tanner 409157c107 Exclude domain joshuamorris.info 2026-11-09 15:57:49 +00:00
3 changed files with 17 additions and 13 deletions
-1
View File
@@ -111,4 +111,3 @@ data.db.bak
data/archive/* data/archive/*
data/backup/* data/backup/*
qotnews.sqlite qotnews.sqlite
praw.ini
+1 -1
View File
@@ -11,7 +11,7 @@ import settings
from feeds import hackernews, reddit, tildes, manual, lobsters from feeds import hackernews, reddit, tildes, manual, lobsters
import utils import utils
INVALID_DOMAINS = ['youtube.com', 'bloomberg.com', 'wsj.com', 'sec.gov'] INVALID_DOMAINS = ['youtube.com', 'bloomberg.com', 'wsj.com', 'sec.gov', 'joshuamorris.info']
TWO_DAYS = 60*60*24*2 TWO_DAYS = 60*60*24*2
def list(): def list():
+16 -11
View File
@@ -10,7 +10,6 @@ SEARCH_ENABLED = bool(settings.MEILI_URL)
def meili_api(method, route, json=None, params=None, parse_json=True): def meili_api(method, route, json=None, params=None, parse_json=True):
try: try:
headers = {'Authorization': 'Bearer ' + settings.MEILI_API_KEY}
r = method(settings.MEILI_URL + route, json=json, params=params, timeout=4) r = method(settings.MEILI_URL + route, json=json, params=params, timeout=4)
if r.status_code > 299: if r.status_code > 299:
raise Exception('Bad response code ' + str(r.status_code)) raise Exception('Bad response code ' + str(r.status_code))
@@ -29,20 +28,24 @@ def create_index():
json = dict(uid='qotnews', primaryKey='id') json = dict(uid='qotnews', primaryKey='id')
return meili_api(requests.post, 'indexes', json=json) return meili_api(requests.post, 'indexes', json=json)
def update_settings(): def update_rankings():
json = { json = ['typo', 'words', 'proximity', 'date:desc', 'exactness']
'rankingRules': ['typo', 'words', 'proximity', 'date:desc', 'exactness'], return meili_api(requests.post, 'indexes/qotnews/settings/ranking-rules', json=json)
'searchableAttributes': ['title', 'url', 'author'],
'displayedAttributes': ['id', 'ref', 'source', 'author', 'author_link', 'score', 'date', 'title', 'link', 'url', 'num_comments'], def update_attributes():
} json = ['title', 'url', 'author']
return meili_api(requests.post, 'indexes/qotnews/settings', json=json) r = meili_api(requests.post, 'indexes/qotnews/settings/searchable-attributes', json=json)
json = ['id', 'ref', 'source', 'author', 'author_link', 'score', 'date', 'title', 'link', 'url', 'num_comments']
r = meili_api(requests.post, 'indexes/qotnews/settings/displayed-attributes', json=json)
return r
def init(): def init():
if not SEARCH_ENABLED: if not SEARCH_ENABLED:
logging.info('Search is not enabled, skipping init.') logging.info('Search is not enabled, skipping init.')
return return
print(create_index()) print(create_index())
update_settings() update_rankings()
update_attributes()
def put_story(story): def put_story(story):
if not SEARCH_ENABLED: return if not SEARCH_ENABLED: return
@@ -50,11 +53,13 @@ def put_story(story):
def search(q): def search(q):
if not SEARCH_ENABLED: return [] if not SEARCH_ENABLED: return []
json = dict(q=q, limit=settings.FEED_LENGTH) params = dict(q=q, limit=settings.FEED_LENGTH)
r = meili_api(requests.post, 'indexes/qotnews/search', json=json, parse_json=False) r = meili_api(requests.get, 'indexes/qotnews/search', params=params, parse_json=False)
return r return r
if __name__ == '__main__': if __name__ == '__main__':
init() init()
print(update_rankings())
print(search('facebook')) print(search('facebook'))