Skip to content
Snippets Groups Projects
Commit 1d71d3d2 authored by Tim's avatar Tim
Browse files

testing alternate follower iteration

parent 0df4fa3d
No related branches found
No related tags found
No related merge requests found
......@@ -26,18 +26,16 @@ def db_last_block():
# api specific
# ------------
def get_followers(account: str, skip: int, limit: int):
q = select([hive_follows]). \
where(hive_follows.c.following == account). \
skip(skip).limit(limit)
return conn.execute(q)
def get_followers(account: str, start = None):
res = query("SELECT follower, created_at FROM hive_follows WHERE following = :account AND "
"created_at < IFNULL(:start, NOW()) ORDER BY created_at DESC LIMIT 10", account = account, start = start)
return [[r[0],r[1]] for r in res.fetchall()]
def get_following(account: str, skip: int, limit: int):
q = select([hive_follows]). \
where(hive_follows.c.follower == account). \
skip(skip).limit(limit)
return conn.execute(q)
def get_following(account: str, start: None):
res = query("SELECT following, created_at FROM hive_follows WHERE follower = :account AND "
"created_at < IFNULL(:start, NOW()) ORDER BY created_at DESC LIMIT 10", account = account, start = start)
return [[r[0],r[1]] for r in res.fetchall()]
def following_count(account: str):
......@@ -52,3 +50,14 @@ def follower_count(account: str):
where(hive_follows.c.following == account). \
as_scalar()
return conn.execute(q)
# following/follower counts
# SELECT SUM(IF(follower = 'roadscape', 1, 0)) following, SUM(IF(following = 'roadscape', 1, 0)) followers FROM hivepy.hive_follows WHERE is_muted = 0;
# notifications -- who reblogged you
# SELECT * FROM hive.hive_reblogs r
# JOIN hive_posts p ON r.post_id = p.id
# WHERE p.author = 'roadscape'
# ORDER BY r.created_at DESC;
......@@ -16,6 +16,16 @@ from hive.sbds.sbds_json import ToStringJSONEncoder
from sqlalchemy import create_engine
from steem.steemd import Steemd
from hive.db.methods import (
get_followers,
get_following,
following_count,
follower_count,
)
logger = logging.getLogger(__name__)
app = bottle.Bottle()
......@@ -50,6 +60,19 @@ def health():
diff=diff,
timestamp=datetime.utcnow().isoformat())
@app.get('/followers/<user>')
def callback(user):
return dict(user = user, followers = get_followers(user))
@app.get('/followers/<user>/<since>')
def callback(user, since):
return dict(user = user, followers = get_followers(user, since))
@app.get('/head_state')
def callback():
return head_state()
# JSON-RPC route
# --------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment