Beispiel #1
0
def auth_endpoint():
    imagekit = ImageKit(
        private_key=current_app.config['IMAGEKIT_PRIVATE_KEY'],
        public_key=current_app.config['IMAGEKIT_PUBLIC_KEY'],
        url_endpoint=current_app.config['IMAGEKIT_URL_ENDPOINT'])
    auth_params = imagekit.get_authentication_parameters()

    return jsonify(auth_params)
Beispiel #2
0
def get_imagekit_urls(
    limit: Optional[int] = 100,
    private_key: Optional[str] = os.environ["IMAGEKIT_PRIVATE_KEY"],
    public_key: Optional[str] = os.environ["IMAGEKIT_PUBLIC_KEY"],
    url_endpoint: Optional[str] = os.environ["IMAGEKIT_URL_ENDPOINT"],
) -> None:
    """gets imagekit urls for a given set of credentials"""

    # flake8: noqa E501
    imagekit = ImageKit(
        private_key=private_key,
        public_key=public_key,
        url_endpoint=url_endpoint,
    )

    print(json.dumps(imagekit.list_files({"limit": limit})))
Beispiel #3
0
def check_connections():
    if not os.environ.get('CLOUDINARY_URL'):
        raise EnvironmentError("ENV {CLOUDINARY_URL} does not exist")

    if not os.environ.get('IMAGEKIT_ID'):
        raise EnvironmentError("ENV {IMAGEKIT_ID} does not exist")
    else:
        IMAGEKIT_ID = os.environ.get('IMAGEKIT_ID')

    if not os.environ.get('IMAGEKIT_PUBLIC_KEY'):
        raise EnvironmentError("ENV {IMAGEKIT_PUBLIC_KEY} does not exist")
    else:
        IMAGEKIT_PUBLIC_KEY=os.environ.get('IMAGEKIT_PUBLIC_KEY')

    if not os.environ.get('IMAGEKIT_PRIVATE_KEY'):
        raise EnvironmentError("ENV {IMAGEKIT_PRIVATE_KEY} does not exist")
    else:
        IMAGEKIT_PRIVATE_KEY=os.environ.get('IMAGEKIT_PRIVATE_KEY')

    try:
        cloudinary.api.usage()
    except Exception as ex:
        raise(ex)

    global imagekit
    imagekit = ImageKit(
        private_key = IMAGEKIT_PRIVATE_KEY,
        public_key = IMAGEKIT_PUBLIC_KEY,
        url_endpoint = 'https://ik.imagekit.io/'+IMAGEKIT_ID
    )
Beispiel #4
0
from imagekitio import ImageKit

DB_NAME = 'data/onomancer.db'
VOTE_THRESHOLD = -4
LEADER_THRESHOLD = -2
ANNOTATE_THRESHOLD = 1

logger = logging.getLogger(__name__)

try:
    with open('data/imagekit.key', 'r') as f:
        imagekit_key = f.read()

    imagekit = ImageKit(
        private_key=imagekit_key,
        public_key='public_sb9Ym97kLySuXDx8WAm0OFVvmWg=',
        url_endpoint='https://ik.imagekit.io/4waizx9and',
    )
except Exception as e:
    imagekit = None
    logger.debug(e)

BAD_EGG_CLAUSE = '''
(
    (
        upvotes-downvotes > 15 AND
        (
            upvotes = 0 OR
            -1.0 * downvotes / upvotes > 0.5
        )
    )
Beispiel #5
0
def get_image_kit_signature(request):
    image_kit = ImageKit(private_key='private_7zgXhRBx6JkdbiffUrT6Iz+RC70=',
                         public_key='public_7/xIjAxG2LvxezZFcU5XVjHQv50=',
                         url_endpoint=' https://ik.imagekit.io/quava')
    return JsonResponse(data=image_kit.get_authentication_parameters())
Beispiel #6
0
from imagekitio import ImageKit
from dotenv import load_dotenv
from pathlib import Path
import os

env_path = Path(".") / ".env"
load_dotenv(dotenv_path=env_path)

PRIVATE_KEY = os.getenv("IMAGEKIT_PRIVATE_KEY")
PUBLIC_KEY = os.getenv("IMAGEKIT_PUBLIC_KEY")
URL_ENDPOINT = os.getenv("URL_ENDPOINT")

imagekit = ImageKit(
    private_key=PRIVATE_KEY,
    public_key=PUBLIC_KEY,
    url_endpoint=URL_ENDPOINT,
)


def upload_image(filepath, filename):
    upload_status = imagekit.upload_file(
        file=open(filepath, "rb"),  # required
        file_name=filename,  # required
    )
    return upload_status


def purge_image(image_id):
    purge_status = imagekit.delete_file(image_id)
    return purge_status
Beispiel #7
0
@app.route('/has_phone_number', methods=['GET'])
def has_phone_number():
    if not current_user.is_authenticated:
        return jsonify({'has_phone_number' : False})
    if current_user.phone_number is None:
        return jsonify({'has_phone_number' : False})
    else:
        return jsonify({'has_phone_number' : True})


from imagekitio import ImageKit

imagekit = ImageKit(
    private_key=app.config['IMAGEKIT_PRIVATE_KEY'],
    public_key=app.config['IMAGEKIT_PUBLIC_KEY'],
    url_endpoint =app.config['IMAGEKIT_URL_ENDPOINT']
)

@app.route('/auth_endpoint', methods=['GET'])
def auth_endpoint():
    auth_params = imagekit.get_authentication_parameters()

    return jsonify(auth_params)


@app.route('/verify_oauth2_token/<token>', methods=['GET'])
def verify_oauth2_token(token):
    try:
        userinfo_response = id_token.verify_oauth2_token(token, requests.Request(),app.config['GOOGLE_CLIENT_ID'])
        unique_id = userinfo_response["sub"]
Beispiel #8
0
import requests
import base64

# Third-party libraries
from flask import Flask, request
from imagekitio import ImageKit

# Internal imports
CLIENT_ID = os.environ.get('CLIENT_ID')
CLIENT_SECRET = os.environ.get('CLIENT_SECRET')
BASE_URL = os.environ.get('BASE_URL')
UPLOADED_PHOTOS_DEST = os.getcwd() + '/static/uploads'

# # Image Kit API
imagekit = ImageKit(private_key=os.getenv('IMG_KIT_PRIVATE_KEY'),
                    public_key=os.getenv('IMG_KIT_PUBLIC_KEY'),
                    url_endpoint=os.getenv('IMG_KIT_URL_ENDPOINT'))

##################################################################
#   MANAGE FILES ON UPLOAD PAGE FUNCTIONS  ----------------------#
##################################################################


def save_file(file, filename):
    """Saves file to uploads folder"""

    file.save(os.path.join(UPLOADED_PHOTOS_DEST, filename))
    print("File saved")


def clear_uploads(file):
#pip install imagekitio
#https://github.com/imagekit-developer/imagekit-python

from imagekitio import ImageKit

#configuration
imagekit = ImageKit(private_key='private_/VE3e+xlNcOda8x5H0rWdJkadH8=',
                    public_key='public_3DO66QF/NddNueQIPN2rVtp3oIE=',
                    url_endpoint='https://ik.imagekit.io/bry5gj5urua')

#uploading files
"""
imagekit.upload_file(
    file= open("imagekitioClient.py", "rb"),
    file_name= "imagekitioClient.py",
    options= {
        "folder" : "/twojkomputerowiec/",
        "tags": ["skrypt testowy"],
        "is_private_file": False,
        "use_unique_file_name": True,
        "response_fields": ["tags"],
    }
)
"""

#listing files
results = imagekit.list_files({
    "path": "/twojkomputerowiec/",
    "skip": 0,
    "limit": 10,
})
Beispiel #10
0
from imagekitio import ImageKit
import json, random, string, time

# I use ImageKit for hosting images. However, you can use what you what. 
imagekit = ImageKit(
    private_key='',
    public_key='',
    url_endpoint = ''
    )

def UploadImage(img, status="", prot="off", password=""):
    if prot == "on":
        prot = True
    else:
        prot = False

    RESULT = imagekit.upload(
    file=open("images/" + img, "rb"),
    file_name= ".png",
    options={
        "response_fields": ["folder"],
        "folder": "imganon"
        }
    )

    # process data and return it to the user
    ikres = RESULT["response"]
    shareid = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for i in range(6))
    expire = int(time.time()) + 86400 * 7
    fileId = ikres["fileId"]
    imgurl = ikres["url"]
Beispiel #11
0
from flask import Flask
from flask_marshmallow import Marshmallow
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
import cloudinary
from imagekitio import ImageKit
from flask_mail import Mail

#test
# from dotenv import load_dotenv
import os

# Config ImageKit
imagekit = ImageKit(
    private_key=os.getenv('PRIVATE_KEY_IMAGEKIT'),
    public_key=os.getenv('PUBLIC_KEY_IMAGEKIT'),
    url_endpoint=os.getenv('URL_ENDPOINT_IMAGEKIT'),
)
UseImagekit = os.getenv('USE_IMAGEKIT')

#Config Cloudinary
cloudinary.config(
    cloud_name=os.getenv('CLOUD_NAME'),
    api_key=os.getenv('API_KEY'),
    api_secret=os.getenv('API_SECRET'),
)
UseCloundiary = os.getenv('USE_CLOUDINARY')

#Config Flask
picFolder = os.path.join('../assets', 'images')
picFolderTempate = os.path.join('../assets', '/template/images')
Beispiel #12
0
import os
import json
import base64
from imagekitio import ImageKit

if os.path.exists('secrets.json'):
    with open('secrets.json') as secret:
        data = json.load(secret)
    secret.close()

imagekit = ImageKit(private_key=data["IMGKT_PRIVATE_KEY"],
                    public_key=data["IMGKT_PUBLIC_KEY"],
                    url_endpoint=data["IMGKT_URL_ENDPOINT"])


def get_image_url(path):
    imagekit_url = imagekit.url({
        "path":
        path,
        "url_endpoint":
        data["IMGKT_URL_ENDPOINT"],
        "transformation": [{
            "height": "300",
            "width": "400"
        }],
    })

    return imagekit_url


def upload_image(file_system, name):
Beispiel #13
0
loginManager.login_message = Konfiguracja.LOGIN_MSG

db = SQLAlchemy(app)
migrate = Migrate(app, db)
bcrypt = Bcrypt(app)
mail = Mail(app)
api = Api(app)
admin = Admin(app, name='', index_view=AdminIndexView(name='Admin'))


class AdminModelView(ModelView):
    def is_accessible(self):
        return current_user.is_authenticated and Konfiguracja.MAIL_USERNAME == current_user.email

    def inaccessible_callback(self, name, **kwargs):
        # redirect to login page if user doesn't have access
        return redirect(url_for('logowanie'))

import cloudinary
if Konfiguracja.STORAGE_PROXY:
    cloudinary.config(cloud_name=Konfiguracja.STORAGE_NAME, api_key=Konfiguracja.STORAGE_KEY, api_secret=Konfiguracja.STORAGE_SEC, api_proxy=Konfiguracja.STORAGE_PROXY)
else:
    cloudinary.config(cloud_name=Konfiguracja.STORAGE_NAME, api_key=Konfiguracja.STORAGE_KEY, api_secret=Konfiguracja.STORAGE_SEC)

from imagekitio import ImageKit
imagekit = ImageKit(
    private_key=Konfiguracja.STORAGE2_SEC,
    public_key=Konfiguracja.STORAGE2_KEY,
    url_endpoint='https://ik.imagekit.io/' + Konfiguracja.STORAGE2_NAME
)
from TwojKomputerowiec import strony, restApi
Beispiel #14
0
from django.db import models
from django.apps import apps
from imagekitio import ImageKit
import os

imagekit = ImageKit(private_key=os.getenv("IMAGEKIT_PRIVATE_KEY"),
                    public_key=os.getenv("IMAGEKIT_PUBLIC_KEY"),
                    url_endpoint=os.getenv("IMAGEKIT_URL"))


class PostManager(models.Manager):
    def get_post(self, id):
        try:
            return self.get(id=id)
        except self.model.DoesNotExist:
            return None

    def create_post(self, title, content, image_data=None):
        new_post = self.create(title=title, content=content)

        apps.get_model("blog",
                       "Image").objects.create_image(post=new_post,
                                                     image_data=image_data)

        return new_post

    def modify_post(self, id, title, content, image_data=None):
        current_post = self.get(id=id)
        current_post.title = title
        current_post.content = content
        current_post.save()