def get_db(): use_redis = os.environ.get('USE_REDIS') in [True, 'true', 'True', '1'] if use_redis: try: return Redpie(0, 'instabot_redis') except ConnectionError: return {} else: return {}
import datetime from flask import Flask, request, redirect, send_from_directory, abort, jsonify import google.oauth2.credentials import google.auth.transport.requests import google_auth_oauthlib.flow from googleapiclient.discovery import build import os from uuid import uuid4 from redpie import Redpie SERVER_URL = os.environ['SERVER_URL'] API_SCOPE = ['https://www.googleapis.com/auth/gmail.readonly'] JSON_FILE = 'oauth_client.json' REDIRECT_URI = f'{SERVER_URL}/oauth2/callback/' app = Flask(__name__, static_folder=".") db = Redpie(1, 'redis') def get_email_body(message): new_element = {} if 'attachmentId' not in message['payload']['body']: if 'parts' not in message['payload']: decoded_body = base64.urlsafe_b64decode( message['payload']['body']['data']).decode('utf-8') new_element[message['payload']['mimeType']] = decoded_body else: for each in message['payload']['parts']: if 'parts' not in each['body']: new_element = get_email_body({'payload': each}) else: decoded_body = base64.urlsafe_b64decode(
KLOYSTER_SALT ) from flask import Flask, request, redirect, make_response, abort, jsonify from functools import wraps import hashlib from io import BytesIO import logging import os from redpie import Redpie from shutil import rmtree from slugify import slugify import zipfile app = Flask('Kloyster', static_folder=os.path.join(os.path.dirname(os.path.abspath(__file__)), WEBS_DIR)) db = Redpie(REDIS_DB, REDIS_HOST, REDIS_PORT) if 'admin' not in db: db['admin'] = encode_p('admin') LOGGER = logging.getLogger() with open('static/upload.html', 'r') as f: upload_web_html = f.read() with open('static/request_password.html', 'r') as f: request_password_html = f.read() def admin(f): @wraps(f) def w(*args, **kwargs):
RCLONE_CONFIG_PATH = None DRIVE_IMAGES_PATH = os.environ.get('DRIVE_IMAGES_PATH', IMAGES_PATH) if RCLONE_CONFIG_PATH: RCLONE_CONFIG = None with open(RCLONE_CONFIG_PATH) as f: RCLONE_CONFIG = f.read() IMAGES_ACCESS_TIME = {} if REDIS_HOST: redis_conf = {'host': REDIS_HOST} if REDIS_DB: redis_conf['db'] = REDIS_DB if REDIS_PORT: redis_conf['port'] = REDIS_PORT db = Redpie(**redis_conf) else: db = {} def move_to_drive_loop(): while True: for img_name in db.keys(): img_data = db[img_name] oldness = (datetime.now() - img_data['accessed_at']).seconds if img_data['location'] == 'cached': if oldness > MAX_SECONDS_BEFORE_DRIVE: if os.path.isfile(f'{IMAGES_PATH}/{img_name}'): os.remove(f'{IMAGES_PATH}/{img_name}') db[img_name] = {'location': 'drive', 'accessed_at': img_data['accessed_at']}
from flask import Flask, abort, jsonify, make_response, redirect, request from flask_cors import CORS from redpie import Redpie SALT = os.environ['SALT'] def encode_p(p): return hashlib.sha256((p + SALT).encode('utf-8')).hexdigest() app = Flask('myFus') CORS(app) db = Redpie( int(os.environ.get('REDIS_DB', 0)), os.environ.get('REDIS_HOST', 'localhost'), int(os.environ.get('REDIS_PORT', 6379)) ) if '_last_key' not in db: db['_last_key'] = 'a' db['_admin'] = encode_p(os.environ['ADMIN_PASSWORD']) LOGGER = logging.getLogger() base = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' with open('upload.html', 'r') as f: upload_html = f.read() with open('admin.html', 'r') as f: admin_html = f.read() def admin(f):
def r(): r = Redpie(10) r.clear() return r
def test_all(r): r['qwe'] = 2 assert r['qwe'] is 2 assert 'qwe' in r assert 'q' not in r del(r['qwe']) with pytest.raises(KeyError): del(r['qwe']) r['qwe'] = 2 assert format(r) == "{'qwe': 2}" i = iter(r) assert next(i) == 'qwe' with pytest.raises(StopIteration): next(i) assert len(r) is 1 r['www'] = 3 assert len(r) is 2 del(r['www']) r.__reduce__() assert r.__repr__() == "{'qwe': 2}" assert r._redis.dbsize() > 0 r.clear() assert r._redis.dbsize() is 0 r['qwe'] = 2 assert r.get('qwe') is 2 assert r.get('w') is None assert r.get('w', 4) is 4 assert type(r.keys()) is type({}.keys()) assert list(r.keys()) == ['qwe'] assert r._redis.dbsize() is 1 assert r.pop('qwe') is 2 with pytest.raises(KeyError): assert r.pop('qwe') assert r._redis.dbsize() is 0 r['qwe'] = 2 key, value = r.popitem() assert key == 'qwe' assert value is 2 with pytest.raises(KeyError): r.popitem() assert r.setdefault('qwe', 1) is 1 assert r.setdefault('qwe', 2) is 1 assert list(r.keys()) == ['qwe'] r.clear() r['qwe'] = 2 r['qqq'] = 3 r.update({'qwe':1, 'zzz':4}) assert r._redis.dbsize() is 3 assert r['qwe'] is 1 assert r['qqq'] is 3 assert r['zzz'] is 4 assert 4 in list(r.values()) assert 1 in list(r.values()) assert 3 in list(r.values()) assert r == {'qwe': 1, 'qqq': 3, 'zzz': 4} assert r != {'aaa': 1, 'bbb': 3, 'zzz': 5} assert r != {'qwe': 1, 'qqq': 3, 'zzz': 5} assert r != 1 assert r != {'w': 2} its = r.items() assert type(its) == type({}.items()) assert ('qwe', 1) in list(its) assert ('qqq', 3) in list(its) assert ('zzz', 4) in list(its) with pytest.raises(KeyError): r['rrr'] with pytest.raises(NotImplementedError): r.fromkeys('qd') with pytest.raises(NotImplementedError): r.copy() r2 = Redpie() print(r2)
import config from datetime import datetime from flask import Flask, request, redirect, send_from_directory from linkedin import Scrapper from redpie import Redpie from werkzeug.exceptions import NotFound app = Flask(__name__) cache = Redpie(0, 'linkedinescrap-redis') cookies = None if '_cookies' in cache: cookies = cache['_cookies'] linkedin_scrapper = Scrapper(config.SCRAP_EMAIL, config.SCRAP_PASS, cookie_jar=cookies) @app.route("/title") def get_title(): email = request.args.get('e') link = request.args.get('l') return linkedin_scrapper.get_title(email=email, link=link) @app.route("/get") def get_linkedin(): email = request.args.get('e') profile = None if email in cache: cached_profile = cache[email]