Exemplo n.º 1
0
 def test_url_should_return_correct_url(self):
     f = FileStorage(open(self.test_image_path))
     file_path = Storage.save(f)
     url = Storage.url(file_path)
     print url
     response = self.client.get(url)
     self.assert200(response)
Exemplo n.º 2
0
def collect(cli):
    if not cli.args:
        cli.error(cli.option)
    else:
        tweets = Collect(cli.args[0]).search()
        Storage('collected').save(tweets)
        cli.success(cli.option)
Exemplo n.º 3
0
def main():
    # 检查存储配置信息
    if not all((ACCESS_KEY, SECRET_KEY, BUCKET_NAME, RESOURCE_PREFIX)):
        notify('⚠️ 警告', '请先设置好相关配置信息!')
        open_editor('app/config.py')
        return

    try:
        """
        文件上传
        """
        image = Clipboard().image
        logging.debug('image info: {image}'.format(image=image))
        local_path = image['file']
        remote_path = '{name}.{postfix}'.format(name=file_hash(local_path),
                                                postfix=image['type'])
        storage = Storage()
        if not storage.is_exist(remote_path):
            storage.upload(local_path, remote_path)
        if image['clean'] is True:
            # 清理磁盘临时文件
            os.remove(local_path)
        notify('📢 通知', '文件上传成功!')
        """
        文件展示
        """
        url = '{prefix}/{path}{template}'.format(
            prefix=RESOURCE_PREFIX.strip('/'),
            path=remote_path,
            template=IMAGE_TEMPLATE)
        if not url.startswith("http://"):
            url = "http://" + url
        # 处理markdown图片模板占位符
        markdown_data = {}
        for item in ('title', 'url'):
            if '{%(mark)s}' % {'mark': item} in MARKDOWN_IMAGE_TEMPLATE:
                if item == 'title':
                    markdown_data['title'] = remote_path
                elif item == 'url':
                    markdown_data['url'] = url
        logging.debug('markdown data: {markdown_data}'.format(
            markdown_data=markdown_data))
        print MARKDOWN_IMAGE_TEMPLATE.format(**markdown_data)
    except exception as e:
        notify('❌ 错误', str(e))
Exemplo n.º 4
0
    def test_storage(self):
        name = "Toshiba P300 HDWD240UZSVA"
        manufacturer = "Toshiba"
        total = 45
        allocated = 45
        capacity_GB = 4000
        internal = False
        external = True

        storage_repr = (f"Storage(name={name}, "
                        f"manufacturer={manufacturer}, "
                        f"total={total}, "
                        f"allocated={allocated}, "
                        f"capacity_GB={capacity_GB}, "
                        f"internal={internal}, "
                        f"external={external})")

        storage = Storage(name, manufacturer, total, allocated, capacity_GB,
                          internal, external)
        self.assertEqual(storage_repr, storage.__repr__())
Exemplo n.º 5
0
    def test_capacity(self):
        name = "Kingston SKC2000M8"
        manufacturer = "Kingston"
        total = 20
        allocated = 19
        capacity_GB = -250
        internal = False
        external = True

        with self.assertRaises(ResourceError):
            storage = Storage(name, manufacturer, total, allocated,
                              capacity_GB, internal, external)
Exemplo n.º 6
0
    def test_str_storage(self):
        name = "Toshiba P300 HDWD240UZSVA"
        manufacturer = "Toshiba"
        total = 45
        allocated = 45
        capacity_GB = 4000
        internal = False
        external = True

        storage = Storage(name, manufacturer, total, allocated, capacity_GB,
                          internal, external)

        self.assertEqual(str(storage), storage.name)
Exemplo n.º 7
0
import json
from time import sleep

from werkzeug.serving import run_simple
from werkzeug.wrappers import Request, Response

from app.storage import Storage
from app.config import ConfigReader
from app.iptables import IPTables

storage = Storage()


def build_response(message: str, code: int):
    """
    Build JSON response.
    """
    return Response(message, content_type='application/json', status=code)


@Request.application
def application(request):
    """
    Define the WSGI application to be run by the server.
    """
    cfg = ConfigReader()
    ipt = IPTables(cfg)

    token = request.args.get('token')
    src_ip = str(request.host)
                        print "{}. {}".format(
                            rooms + 1, Storage.list_of_all_rooms[size].
                            Room_instance.current_members[rooms])
                else:
                    print "Room is empty."
                    break
                    return None
            else:
                if size + 1 == len(Storage.list_of_all_rooms):
                    print "Sorry!! That room doesn't exist."
                    break
                    return None


if __name__ == '__main__':
    store = Storage()
    amity = Amity()

    amity.createRoom("Hogwards")
    amity.createRoom("Narnia")

    amity.allocateRoom("marvin kang", "FELLOW", "YES")

    amity.reallocate_person(1234, "Hogwards")

# 	amity.createRoom("Camelot")
# 	amity.createRoom("Mordor")

# 	for size in range(len(store.list_of_all_rooms)):
# 		print store.list_of_all_rooms[size].Room_name
"""
Exemplo n.º 9
0
def prediction():
    collect_files = Storage('collected').load()
    trained_files = Storage('trained').load()

    Mining(collect_files, trained_files).start()
Exemplo n.º 10
0
def training():
    data = Storage('collected').load()
    tweets = Training(data).evaluate()
    Storage('trained').save(tweets)
Exemplo n.º 11
0
if __name__ == '__main__':
    """
    Human-Machine Interface
    """
    cli = Cli()
    start(cli)

    while cli.option != 'x':
        if cli.option == 'h':
            display_help(cli)
        elif cli.option == 'c' or cli.option == "collect":
            collect(cli)
        elif cli.option == 't' or cli.option == "training":
            training()
        elif cli.option == 'p' or cli.option == "prediction":
            prediction()
        elif cli.option == 'tweets':
            data = Storage('collected').load()
            cli.tweets_colleted(data)
        elif cli.option == 'tweets trained':
            data = Storage('trained').load()
            cli.tweets_trained(data)
        elif cli.option == 'tweets metrics':
            collected = Storage('collected').load()
            trained = Storage('trained').load()
            cli.tweets_metrics(collected, trained)

        cli.waiting_input()

    cli.finished()