Пример #1
0
    def __init__(self, user_data, username=False, count=500):
        self.id = user_data['_id']
        self.screen_name = user_data['twitter']['screen_name']
        if username:
            self.screen_name = username
        self.access_token = user_data['twitter']['access_token']
        self.access_token_secret = user_data['twitter']['access_secret_token']
        self.auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        self.auth.set_access_token(self.access_token, self.access_token_secret)
        client = pymongo.MongoClient(os.environ['DB_STRING'], connect=False)
        self.db = client.get_database()
        self.firefly_client = firefly.Client(PREDICT_URL,
                                             auth_token='cortexai')

        try:
            self.api = tweepy.API(self.auth)
            self.me = self.api.me()
            self.start_time = time.time()
        except Exception as e:
            print(e)
Пример #2
0
"""Script to call the credit-risk API
"""
import firefly

api = firefly.Client("https://credit-scoring-demo.rorocloud.io/")

row = {
    'delinq_2yrs': 0.0,
    'delinq_2yrs_zero': 1.0,
    'dti': 8.7200000000000006,
    'emp_length_num': 0,
    'grade': 'F',
    'home_ownership': 'RENT',
    'inq_last_6mths': 3.0,
    'last_delinq_none': 1,
    'last_major_derog_none': 1,
    'open_acc': 2.0,
    'payment_inc_ratio': 4.5,
    'pub_rec': 0.0,
    'pub_rec_zero': 1.0,
    'purpose': 'vacation',
    'revol_util': 98.5,
    'short_emp': 0,
    'sub_grade_num': 1.0
}

result = api.predict(row=row)
print(result)
Пример #3
0
"""Script to call the background-removal API with an image.

USAGE: python test.py static/bird.jpg
"""
import firefly
import sys
import shutil

background_removal = firefly.Client(
    "https://background-removal--api.rorocloud.io/")


def main():
    image_path = sys.argv[1]
    format = image_path.split(".")[-1]

    print("calling the background removal API...")
    new_image = background_removal.predict(image_file=open(image_path, 'rb'),
                                           format=format)

    ## To open Image using PIL
    # from PIL import Image
    # img = Image.open(new_image)

    with open("output.jpg", "wb") as f:
        shutil.copyfileobj(new_image, f)
    print("saved the output image in output.jpg")


if __name__ == '__main__':
    main()
"""Script to call the background-removal API with an image.

USAGE: python test.py static/bird.jpg
"""
import firefly
import sys
import shutil
import base64

background_removal = firefly.Client(
    "https://test-background-removal.rorocloud.io")


def main():
    image_path = sys.argv[1]
    # format = image_path.split(".")[-1]
    # print(image_path)

    print("calling the background removal API...")
    new_image = background_removal.predict(image=image_path)

    ## To open Image using PIL
    # from PIL import Image
    # img = Image.open(new_image)
    img_decode = base64.b64decode(new_image["data"])
    with open("output.png", "wb") as f:
        f.write(img_decode)
    print("saved the output image in output.jpg")


if __name__ == '__main__':
Пример #5
0
import firefly as ff
client = ff.Client(
    input("Firefly url: "))  # e.g. https://school.fireflycloud.net/
client.set_cookies(input("Cookies: "))

client.filter.sorting = ff.task.TaskFilter.Sorting(
    column=ff.task.TaskFilter.Sorting.Column.DUE_DATE,
    order=ff.task.TaskFilter.Sorting.Order.DESCENDING)
# client.filter.completion_status = ff.task.TaskFilter.CompletionStatus.TO_DO
client.filter.page_size = 2


def on_update(page, page_size, val):
    print(val, page)


client._get_tasks(page=0)
for task in client.tasks:
    print("#########################")
    print(task.title, "-", task.setter.name, "-", task.student.name)
    print("[", task.id, "]\n")
    print(task.description)
    print()

client.tasks[0].toggle_done()
client.tasks[0].send_comment("Test")
Пример #6
0
def just_login(email, password):
    client = firefly.Client(config.SERVER_URL)
    token = client.login(email=email, password=password)
    return token
Пример #7
0
"""Script to test the recommender system API
"""
import firefly

api = firefly.Client("https://recommender-system-demo.rorocloud.io/")

result = api.predict(user_id=25)
print(result)
Пример #8
0
"""Script to call the background-removal API with an image.

USAGE: python test.py static/bird.jpg
"""
import firefly
import sys
import shutil
import yaml
import base64

config = yaml.safe_load(open("rorolite.yml"))
host = config['host']
port = config['services'][0]['port']

api = firefly.Client("http://{}:{}".format(host, port))

default_image_url = "https://rorodata-tmp.s3.amazonaws.com/liomessi.jpg"


def main():
    try:
        image_url = sys.argv[1]
    except IndexError:
        image_url = default_image_url

    print("calling the background removal API...")
    response = api.predict(image={"url": image_url})

    image_bytes = base64.b64decode(response['data'])
    with open("output.png", "wb") as f:
        f.write(image_bytes)
Пример #9
0
"""The loans database.

This module manages saving the loans into files and reading them back.
"""
import datetime
import pathlib
import json
import firefly

LOANS_DIR = "/data/loans"

credit_grade_api = firefly.Client(
    "https://credit-risk-demo--creditgrade.rorocloud.io/")
api = firefly.Client("https://credit-risk-demo--api.rorocloud.io/")


def get_loans():
    """Returns all the existing loans.
    """
    path = pathlib.Path(LOANS_DIR)
    path.mkdir(exist_ok=True)

    loans = []
    for p in path.glob("*.loan"):
        loan = json.loads(p.read_text(encoding='utf-8'))
        loans.append(loan)
    return sorted(loans, reverse=True, key=lambda loan: loan['timestamp'])


def save_loan(name, email, amount, duration, age, ownership, income):
    grade = find_credit_grade(email)
Пример #10
0
import firefly

client = firefly.Client("http://127.0.0.1:8000/")
r = client.square(n=4)
print(r)