added endpoint to get most popular circles

master
Kevin Froman 2020-03-28 02:41:23 -05:00
parent 825c576ce3
commit b256db2698
4 changed files with 38 additions and 19 deletions

View File

@ -5,7 +5,7 @@ gevent==1.4.0
Flask==1.1.1
PySocks==1.7.1
stem==1.8.0
deadsimplekv==0.3.0
deadsimplekv==0.3.1
unpaddedbase32==0.2.0
streamedrequests==1.0.0
jinja2==2.11.1

View File

@ -46,9 +46,9 @@ click==7.0 \
--hash=sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13 \
--hash=sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7 \
# via flask
deadsimplekv==0.3.0 \
--hash=sha256:66a96e648f1306433628d1b7e2cc2d828d9aa488ad95f2b641a15cd5f89814fa \
--hash=sha256:ac9cf72f8a8e26933d572b7fb607cee84604aab5d9f3a4fd6bf6046818c5d4fc \
deadsimplekv==0.3.1 \
--hash=sha256:85aaacba793178018210728d104c95ddec7755b419b41621310e109fc24cff46 \
--hash=sha256:a61e3f783f5698543d1011ec0ce72b252e950ca2af15e565b43ccc7886213311 \
# via -r requirements.in
filenuke==0.0.0 \
--hash=sha256:147011c0125121469cae0a8a7f4df399f470e54aa29a08f2d2c099bf0118dcee \

View File

@ -2,6 +2,7 @@
This file primarily serves to allow specific fetching of circles board messages
"""
import operator
import json
import os
@ -26,17 +27,20 @@ from utils import identifyhome
flask_blueprint = Blueprint('circles', __name__)
with open(os.path.dirname(os.path.realpath(__file__)) + '/info.json', 'r') as info_file:
with open(
os.path.dirname(
os.path.realpath(__file__)) + '/info.json', 'r') as info_file:
data = info_file.read().strip()
version = json.loads(data, strict=False)['version']
BOARD_CACHE_FILE = identifyhome.identify_home() + '/board-index.cache.json',
BOARD_CACHE_FILE = identifyhome.identify_home() + '/board-index.cache.json'
read_only_cache = DeadSimpleKV(
BOARD_CACHE_FILE,
flush_on_exit=False,
refresh_seconds=30)
@flask_blueprint.route('/circles/getpostsbyboard/<board>')
def get_post_by_board(board):
board_cache = DeadSimpleKV(
@ -50,6 +54,7 @@ def get_post_by_board(board):
posts = ','.join(posts)
return Response(posts)
@flask_blueprint.route('/circles/getpostsbyboard/<board>/<offset>')
def get_post_by_board_with_offset(board, offset):
offset = int(offset)
@ -66,11 +71,14 @@ def get_post_by_board_with_offset(board, offset):
posts = ','.join(posts[offset:offset + OFFSET_COUNT])
return Response(posts)
@flask_blueprint.route('/circles/version')
def get_version():
return Response(version)
@flask_blueprint.route('/circles/removefromcache/<board>/<name>', methods=['POST'])
@flask_blueprint.route('/circles/removefromcache/<board>/<name>',
methods=['POST'])
def remove_from_cache(board, name):
board_cache = DeadSimpleKV(BOARD_CACHE_FILE,
flush_on_exit=False)
@ -83,7 +91,18 @@ def remove_from_cache(board, name):
board_cache.put(board, posts)
return Response('success')
#@flask_blueprint.route('/circles/getpopular/<count>')
#def get_popular(count):
#boards = read_only_cache.get
@flask_blueprint.route('/circles/getpopular/<count>')
def get_popular(count):
boards = json.loads(read_only_cache.get_raw_json())
for board in boards:
boards[board] = len(boards[board])
top_boards = sorted(boards.items(), key=operator.itemgetter(1), reverse=True)[:int(count)]
only_board_names = []
for b in top_boards:
only_board_names.append(b[0])
return Response(','.join(only_board_names), content_type='text/csv')

View File

@ -7,16 +7,16 @@
},
"general": {
"announce_node": true,
"dev_mode": false,
"dev_mode": true,
"display_header": true,
"ephemeral_tunnels": false,
"hide_created_blocks": true,
"insert_deniable_blocks": true,
"insert_deniable_blocks": false,
"max_block_age": 2678400,
"minimum_block_pow": 5,
"minimum_send_pow": 5,
"minimum_block_pow": 1,
"minimum_send_pow": 1,
"public_key": "",
"random_bind_ip": true,
"random_bind_ip": false,
"security_level": 0,
"show_notifications": true,
"store_plaintext_blocks": true,
@ -30,12 +30,12 @@
},
"file": {
"output": true,
"remove_on_exit": true
"remove_on_exit": false
},
"verbosity": "default"
},
"onboarding": {
"done": false
"done": true
},
"peers": {
"max_connect": 1000,
@ -64,7 +64,7 @@
"transports": {
"lan": true,
"manual_disk": true,
"tor": true
"tor": false
},
"ui": {
"theme": "dark"