WIP notes for an open source implementation of Masstagger
api_doc.yml
-> API idea.usercript.js
-> Userscript implementation ideas.app.py
-> Boring flask sample.
swagger: "2.0" | |
info: | |
description: "Open source reddit masstagging server API inspired by masstagger." | |
version: "1.0.0" | |
title: "masstagged" | |
license: | |
name: "AGPLv3.0" | |
url: "http://www.gnu.org/licenses/agpl-3.0.html" | |
host: "myhost.com" | |
basePath: "/api" | |
tags: | |
- name: "user" | |
description: "User related operations" | |
- name: "meta" | |
description: "Metadata queries" | |
schemes: | |
- "https" | |
paths: | |
/user/{username}: | |
get: | |
tags: | |
- "user" | |
summary: "Get the posting history of {username}" | |
description: "" | |
produces: | |
- "application/json" | |
parameters: | |
- in: "path" | |
type: "string" | |
name: "username" | |
description: "Username that has been requested" | |
required: true | |
responses: | |
200: | |
description: "Response succeeded" | |
schema: | |
$ref: "#/definitions/User" | |
400: | |
description: "This user hasn't posted in a marked subreddit" | |
/info: | |
get: | |
summary: "Get an overview of the server" | |
tags: | |
- "meta" | |
responses: | |
200: | |
description: "Response succeeded" | |
schema: | |
$ref: "#/definitions/Overview" | |
/: | |
get: | |
summary: "Check the server status (also this server is a teapot)" | |
tags: | |
- "meta" | |
responses: | |
418: | |
description: "I'm a teapot" | |
schema: | |
$ref: "#/definitions/Teapot" | |
definitions: | |
User: | |
type: "object" | |
properties: | |
username: | |
type: "string" | |
posted_in: | |
type: "array" | |
items: | |
type: "string" | |
Overview: | |
type: "object" | |
properties: | |
total_users: | |
type: "integer" | |
subreddits: | |
type: "array" | |
items: | |
$ref: "#/definitions/Subreddit" | |
Subreddit: | |
type: "object" | |
properties: | |
name: | |
type: "string" | |
reason: | |
type: "string" | |
Teapot: | |
type: "object" | |
properties: | |
is_up: | |
type: "string" |
import json | |
import validators | |
import re | |
from flask import Flask, request | |
app = Flask(__name__) | |
user_regex = re.compile(r"https?:\/\/(?:.*\.)?reddit.com\/u(?:ser)?\/(.*)") | |
with open("data.json", "r") as datafile: | |
jdata = json.load(datafile) | |
@app.route('/') | |
def hello_world(): | |
return 'Hello, World!' | |
@app.route('/bulk_users') | |
def get_bulk_users(): | |
user_urls = request.args.getlist("urls") | |
if user_urls: | |
results = {} | |
for item in user_urls: | |
if validators.url(item): | |
res = user_regex.search(item) | |
if res: | |
username = res.group(1) | |
info = jdata["users"].get(username.lower()) | |
results[username] = info | |
else: | |
return {"status": "Failure", "message": "One of your submitted items was not a URL!"} | |
return results | |
else: | |
return {"status": "Failure", "message": "You need to supply the urls parameter."} |
{ | |
"users": { | |
"bogus": { | |
"shit_sub": 1 | |
} | |
} | |
} |
function addHelloWorldAfterElement(refNode) { | |
var el = document.createElement("span"); | |
el.innerHTML = "HelloWorld"; | |
refNode.parentNode.insertBefore(el, refNode.nextSibling); | |
} | |
document.querySelectorAll(".author").forEach(function(node) { | |
addHelloWorldAfterElement(node); | |
}); |