예제 #1
0
import flask.json
import sqlalchemy
from sqlalchemy.dialects.postgresql import insert

import www.utils
from www import server
from common.config import config, from_apipass
from common import utils
from common import twitch
from common import game_data
from common import googlecalendar
import common.rpc

with server.db.engine.begin() as conn:
    users = server.db.metadata.tables["users"]
    for key, name in from_apipass.items():
        query = insert(users) \
         .values(id=sqlalchemy.bindparam("_id")) \
         .returning(users.c.id)
        query = query.on_conflict_do_update(
            index_elements=[users.c.id],
            set_={
                'name': query.excluded.name,
                'display_name': query.excluded.display_name,
            },
        )
        from_apipass[key], = conn.execute(query, twitch.get_user(name)).first()

# See https://github.com/justintv/Twitch-API/blob/master/authentication.md#scopes
# We don't actually need, or want, any at present
REQUEST_SCOPES = []
예제 #2
0
파일: login.py 프로젝트: andreasots/lrrbot
import flask
import flask.json
import sqlalchemy
from sqlalchemy.dialects.postgresql import insert

import www.utils
from www import server
from common.config import config, from_apipass
from common import utils
from common import http
from common import twitch
from common import game_data
from common import googlecalendar
import common.rpc

for key, name in from_apipass.items():
	from_apipass[key] = twitch.get_user(name=name).id

# See https://dev.twitch.tv/docs/v5/guides/authentication/#scopes
# We don't actually need, or want, any at present
REQUEST_SCOPES = []

SPECIAL_USERS = {}
SPECIAL_USERS.setdefault(config["username"], list(REQUEST_SCOPES)).extend(['chat_login', 'user_read', 'user_follows_edit'])
SPECIAL_USERS.setdefault(config["channel"], list(REQUEST_SCOPES)).extend(['channel_subscriptions'])

def with_session(func):
	"""
	Pass the current login session information to the function

	Usage: