예제 #1
0
def get_comments_raw(oid: int,
                     type_: str,
                     order: str = "time",
                     pn: int = 1,
                     verify: utils.Verify = None):
    """
    通用获取评论
    :param oid:
    :param type_:
    :param order:
    :param pn:
    :param verify:
    :return:
    """
    if verify is None:
        verify = utils.Verify()

    type_ = COMMENT_TYPE_MAP.get(type_, None)
    assert type_ is not None, exceptions.BilibiliApiException("不支持的评论类型")

    order = COMMENT_SORT_MAP.get(order, None)
    assert order is not None, exceptions.BilibiliApiException(
        "不支持的排序方式,支持:time(时间倒序),like(热度倒序)")
    # 参数检查完毕
    params = {"oid": oid, "type": type_, "sort": order, "pn": pn}
    #comment_api = API["common"]["comment"]
    #api = comment_api.get("get", None)
    api = {}
    api["url"] = "https://api.bilibili.com/x/v2/reply"
    resp = get_response(api["url"],
                        params=params,
                        cookies=verify.get_cookies())
    return resp
예제 #2
0
def GetResult(model):
    df = GetDataFrame()
    dists = []
    labels = []
    for idx in tqdm(range(len(df))):
        path1 = join(dir_image, df.loc[idx, 'img1'])
        path2 = join(dir_image, df.loc[idx, 'img2'])
        if (not isfile(path1)) or (not isfile(path2)):
            continue
        dist = Verify(path1, path2, model)
        dists.append(dist)
        labels.append(df.loc[idx, 'class'])

    labels = np.array(labels)
    dists = np.array(dists)
    return labels, dists
예제 #3
0
def _VerifyFolder(path_to_folder, model):
    paths = listdir(path_to_folder)
    assert len(paths) == 2
    path01 = join(path_to_folder, paths[0])
    path02 = join(path_to_folder, paths[1])
    dist = Verify(path01, path02, model)
    result = 'same' if dist < threshold else 'different'
    color = (0, 255, 0) if dist < threshold else (255, 0, 0)

    img1 = Inputs2ArrayImage(path01, dtype=np.uint8)
    img2 = Inputs2ArrayImage(path02, dtype=np.uint8)
    img_merged = MergeImage(img1, img2, color=color)

    name1 = _GetPersonName(paths[0])
    name2 = _GetPersonName(paths[1])

    title = '(' + name1 + ')' + ' - ' + result + ' - ' + '(' + name2 + ')'
    return img_merged, title
예제 #4
0
    d1 = env.from_elements(1, 6, 12)

    d2 = env.from_elements((1, 0.5, "hello", True), (2, 0.4, "world", False))

    d3 = env.from_elements(("hello",), ("world",))

    d4 = env.from_elements((1, 0.5, "hello", True), (1, 0.4, "hello", False), (1, 0.5, "hello", True), (2, 0.4, "world", False))

    d5 = env.from_elements((1, 2.4), (1, 3.7), (1, 0.4), (1, 5.4))

    d6 = env.from_elements(1, 1, 12)

    d7 = env.generate_sequence(0, 999)

    #Generate Sequence Source
    d7.map(Id()).map_partition(Verify(range(1000), "Sequence")).output()

    #Zip with Index
    #check that IDs (first field of each element) are consecutive
    d7.zip_with_index()\
        .map(lambda x: x[0])\
        .map_partition(Verify(range(1000), "ZipWithIndex")).output()

    #CSV Source/Sink
    csv_data = env.read_csv("src/test/python/org/apache/flink/python/api/data_csv", (INT, INT, STRING))

    csv_data.write_csv("/tmp/flink/result1", line_delimiter="\n", field_delimiter="|", write_mode=WriteMode.OVERWRITE)

    #Text Source/Sink
    text_data = env.read_text("src/test/python/org/apache/flink/python/api/data_text")
예제 #5
0
    d5 = env.from_elements((4.4, 4.3, 1), (4.3, 4.4, 1), (4.2, 4.1, 3),
                           (4.1, 4.1, 3))

    d6 = env.from_elements(1, 1, 12)

    #Join
    class Join(JoinFunction):
        def join(self, value1, value2):
            if value1[3]:
                return value2[0] + str(value1[0])
            else:
                return value2[0] + str(value1[1])
    d2 \
        .join(d3).where(2).equal_to(0).using(Join()) \
        .map_partition(Verify(["hello1", "world0.4"], "Join")).output()
    d2 \
        .join(d3).where(lambda x: x[2]).equal_to(0).using(Join()) \
        .map_partition(Verify(["hello1", "world0.4"], "JoinWithKeySelector")).output()
    d2 \
        .join(d3).where(2).equal_to(0).project_first(0, 3).project_second(0) \
        .map_partition(Verify([(1, True, "hello"), (2, False, "world")], "Project Join")).output()
    d2 \
        .join(d3).where(2).equal_to(0) \
        .map_partition(Verify([((1, 0.5, "hello", True), ("hello",)), ((2, 0.4, "world", False), ("world",))], "Default Join")).output()

    #Cross
    class Cross(CrossFunction):
        def cross(self, value1, value2):
            return (value1, value2[3])
    d1 \
예제 #6
0
################################################################################
from flink.plan.Environment import get_environment
from flink.functions.MapFunction import MapFunction
from flink.functions.CrossFunction import CrossFunction
from flink.functions.JoinFunction import JoinFunction
from flink.functions.CoGroupFunction import CoGroupFunction
from flink.functions.Aggregation import Max, Min, Sum
from utils import Verify, Verify2, Id

# Test multiple jobs in one Python plan file
if __name__ == "__main__":
    env = get_environment()
    env.set_parallelism(1)

    d1 = env.from_elements(1, 6, 12)
    d1 \
        .first(1) \
        .map_partition(Verify([1], "First with multiple jobs in one Python plan file")).output()

    env.execute(local=True)

    env2 = get_environment()
    env2.set_parallelism(1)

    d2 = env2.from_elements(1, 1, 12)
    d2 \
        .map(lambda x: x * 2) \
        .map_partition(Verify([2, 2, 24], "Lambda Map with multiple jobs in one Python plan file")).output()

    env2.execute(local=True)
예제 #7
0
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
################################################################################
from flink.plan.Environment import get_environment
import sys
from utils import Verify

if __name__ == "__main__":
    env = get_environment()

    d1 = env.from_elements(len(sys.argv))

    d1.map_partition(Verify([1], "NoArgument")).output()

    #Execution
    env.set_parallelism(1)

    env.execute(local=True)
예제 #8
0
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
################################################################################
from flink.plan.Environment import get_environment
import sys
from utils import Verify

if __name__ == "__main__":
    env = get_environment()

    d1 = env.from_elements(len(sys.argv))

    d1.map_partition(Verify([3], "MultipleArguments")).output()

    #Execution
    env.set_parallelism(1)

    env.execute(local=True)