Ejemplo n.º 1
0
 def __init__(self):
     """Load credentials and initialize Firebase app."""
     cert = env.str('GOOGLE_APPLICATION_CREDENTIALS')
     if cert.startswith('{'):
         cert = json.loads(cert)
     cred = credentials.Certificate(cert)
     if len(firebase_admin._apps) == 0:
         firebase_admin.initialize_app(cred)
     self.db = firestore.client()
Ejemplo n.º 2
0
from nazurin.config import env

PRIORITY = 10

COLLECTION = 'pixiv'
DOCUMENT = 'pixiv'

with env.prefixed('PIXIV_'):
    REFRESH_TOKEN = env.str('TOKEN', default=None)

    IMG_PROXY = env.str('MIRROR', default='i.pximg.net')
    TRANSLATION = env.str('TRANSLATION', default=None)

HEADERS = {'Referer': 'https://app-api.pixiv.net/'}
Ejemplo n.º 3
0
 def __init__(self):
     """Load credentials and initialize client."""
     URI = env.str('MONGO_URI', default='mongodb://localhost:27017/nazurin')
     self.client = AsyncIOMotorClient(URI)
     self.db = self.client.get_default_database()
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-
import asyncio
from typing import List

from mega import Mega as mega
from mega.errors import RequestError

from nazurin.config import NAZURIN_DATA, STORAGE_DIR, env
from nazurin.database import Database
from nazurin.models import File
from nazurin.utils import logger
from nazurin.utils.decorators import async_wrap

MEGA_USER = env.str('MEGA_USER')
MEGA_PASS = env.str('MEGA_PASS')
MEGA_DOCUMENT = 'mega'

class Mega(object):
    api = mega()
    db = Database().driver()
    collection = db.collection(NAZURIN_DATA)
    document = collection.document(MEGA_DOCUMENT)
    destination = None

    api_login = async_wrap(api.login)
    api_upload = async_wrap(api.upload)
    create_folder = async_wrap(api.create_folder)
    find_folder = async_wrap(api.find)

    async def login(self, initialize=False):
        await Mega.api_login(MEGA_USER, MEGA_PASS)
Ejemplo n.º 5
0
from nazurin.config import env

PRIORITY = 9
COLLECTION = 'wallhaven'

with env.prefixed('WALLHAVEN_'):
    API_KEY = env.str('API_KEY', default=None)
Ejemplo n.º 6
0
import asyncio
import json
from typing import List

from oauth2client.service_account import ServiceAccountCredentials
from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive as GDrive

from nazurin.config import env
from nazurin.models import File
from nazurin.utils.decorators import async_wrap
from nazurin.utils.exceptions import NazurinError

GD_FOLDER = env.str('GD_FOLDER')
GD_CREDENTIALS = env.str('GD_CREDENTIALS',
                         default=env.str('GOOGLE_APPLICATION_CREDENTIALS'))


class GoogleDrive(object):
    """Google Drive driver."""
    drive = None

    def __init__(self):
        """Initialize and log in."""
        self.auth()

    def auth(self):
        if GoogleDrive.drive:
            return
        gauth = GoogleAuth()
        scope = ['https://www.googleapis.com/auth/drive']
Ejemplo n.º 7
0
import asyncio
import time
from typing import List, Optional

import aiofiles

from nazurin.config import NAZURIN_DATA, STORAGE_DIR, env
from nazurin.database import Database
from nazurin.models import File
from nazurin.utils import Request, logger

OD_FOLDER = STORAGE_DIR
OD_CLIENT = env.str('OD_CLIENT')
OD_SECRET = env.str('OD_SECRET')
OD_RF_TOKEN = env.str('OD_RF_TOKEN')  # Refresh token for first-time auth
OD_DOCUMENT = 'onedrive'


class OneDrive(object):
    """OneDrive driver."""
    db = Database().driver()
    collection = db.collection(NAZURIN_DATA)
    document = collection.document(OD_DOCUMENT)

    access_token = None
    refresh_token = None
    expires_at = 0
    folder_id = None

    async def upload(self, file: File):
        # https://docs.microsoft.com/zh-cn/graph/api/driveitem-createuploadsession?view=graph-rest-1.0
Ejemplo n.º 8
0
from cloudant.client import Cloudant as cloudant
from requests.adapters import HTTPAdapter

from nazurin.config import RETRIES, env
from nazurin.utils.decorators import async_wrap

with env.prefixed('CLOUDANT_'):
    USERNAME = env.str('USER')
    APIKEY = env.str('APIKEY')
    DATABASE = env.str('DB', default='nazurin')


class Cloudant(object):
    """Cloudant driver of IBM Cloud."""
    def __init__(self):
        """Connect to database."""
        self.client = cloudant.iam(USERNAME,
                                   APIKEY,
                                   timeout=5,
                                   adapter=HTTPAdapter(max_retries=RETRIES))
        self.client.connect()
        self.db = self.client[DATABASE]

    def collection(self, key):
        self._partition = str(key)
        return self

    def document(self, key=None):
        self._document = str(key)
        return self