Giter VIP home page Giter VIP logo

api's Introduction

Hacker News Filter

Overview

This project queries Hackernews for stories, then filters them based on popularity and interests using OPA.

See the demo to see it in action, clone to run it yourself, and configure it as desired

Demo

Hackernews Filter Demo

In the demo, you can see three steps:

  1. Run OPA - as explained in the next section, we run a local copy of OPA
  2. Run HN Filter - in this step we simply start the server
  3. Example - in this step we open localhost and click on fetching popular stories

Quickstart

To run this project, start by installing & running OPA:

Building OPA:

Create an virtualenv and install the requirements:

  virtualenv env
  source env/bin/activate
  pip install -r requirements.txt

Running OPA:

  opa run -s opa_files/policy.rego opa_files/data.json --log-level debug --log-format text

Note that we are running OPA with 2 files:

  • policy.rego - this file holds the filtering logic
  • data.json - this file holds a map between a topic and keywords relevant to the topic

Run the project with:

  uvicorn main:app --reload

Configuration

To configure the filters:

Filter by popularity

Popular stories are stories that have more than 100 upvotes. To change the min. score for a story to be counted as popuplar open policy.rego and change the value

Filter by topic

Stories can be filtered based on their topic as well. The policy code checks for keywords in the title of the article. The supported interests are listed in data\topics.py

  • To alter what keywords define a topic, update data.json and restart OPA (no need to restart the server)
  • To add a new topic of interest, add it both in data\topics.json, and in the data/topics.py file, then restart OPA and restart the server

Project configuration

  • OPA runs on port 8181
  • The HN Filter runs on port 8000

Tech stack

Hackernews articles are returned from Hacker news API - https://github.com/HackerNews/API

OPA policy is here - https://github.com/open-policy-agent/opa

api's People

Contributors

ozradi avatar kogir avatar gruseom avatar sctb avatar kelukelugames avatar ajmeese7 avatar apepper avatar anttimaki avatar edwardbetts avatar louis993546 avatar rosswaycaster avatar shawwn avatar munrocape avatar wcember avatar r3c0d3x avatar gxfr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.