You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
suchwow/suchwow/utils/helpers.py

57 lines
1.5 KiB

from requests import post as r_post
from json import dumps
from flask import session, current_app
from suchwow.models import Moderator, Post
from suchwow.wownero import Wallet
from suchwow import config
def allowed_file(filename):
return "." in filename and \
filename.rsplit(".", 1)[1].lower() in config.ALLOWED_EXTENSIONS
def is_moderator(username):
m = Moderator.filter(username=username)
if m:
return True
else:
return False
def get_session_user():
if "auth" not in session or not session["auth"]:
return None
return session["auth"]["preferred_username"]
def post_webhook(msg):
try:
if current_app.config["DEBUG"]:
msg = "[DEBUG] " + msg
data = {
"text": msg,
"channel": config.MM_CHANNEL,
"username": config.MM_USERNAME,
"icon_url": config.MM_ICON
}
res = r_post(config.MM_ENDPOINT, data=dumps(data))
res.raise_for_status()
return True
except:
return False
def get_activity():
posts = Post.select()
w = Wallet()
data = {}
for p in posts:
data[p.timestamp] = {'type': 'post', 'post': p}
for tx in w.incoming_transfers(p.account_index):
if 'timestamp' in tx:
data[tx['timestamp']] = {'type': 'tx', 'post': p}
dates = sorted(data, reverse=True)
new_data = []
for d in dates:
new_data.append(data[d]['post'])
return new_data[0:20]