コード例 #1
0
def team():

    import time
    if request.method == 'POST':
        schoolName = request.form.get('schoolName')
        institutionName = request.form.get('institutionName')
    if not schoolName:
        schoolName = session['institution_info']['school_name']
        institutionName = session['institution_info']['institution_name']
    with ClusterRpcProxy(CONFIG) as rpc:
        try:
            institutionId = rpc.document.get_institutionId(
                schoolName, institutionName)[0]
        except BaseException as e:
            flash(u"没有此学院信息")
            return render_template("index.html")
        maindis = rpc.document.get_maindis(institutionId)

    for i in maindis:
        try:
            with ClusterRpcProxy(CONFIG) as rpc:
                discipline_name = rpc.document.get_discipline(int(i[0]))
                i[0] = discipline_name
        except:
            pass
    info_maindis = {}
    for i in maindis:
        info_maindis[i[0]] = i[1]
    with ClusterRpcProxy(CONFIG) as rpc:
        mainlab = rpc.document.get_lab(schoolName, institutionName)

    time = time.strftime("%Y:%m")
    a = time.split(":")
    if len(str(int(a[1]) - 2)) == 1:
        mouth = "0" + str(int(a[1]) - 2)
    else:
        mouth = str(int(a[1]) - 2)
    time = str(int(a[0]) - 2) + mouth + "-" + a[0] + a[1]
    #学院信息
    institution_info = {}
    institution_info['school_name'] = schoolName
    institution_info['institution_name'] = institutionName
    institution_info['date'] = time
    institution_info['maindis'] = info_maindis
    institution_info['mainlab'] = mainlab
    # print(institution_info)

    #TODO 处理院系老师之间的关系
    #获取学院中所有老师的名字
    with ClusterRpcProxy(CONFIG) as rpc:
        teacher = rpc.document.get_teacher_info(institutionId)
    teacherlist = []
    for i in teacher:
        teacherlist.append(i[1])

    #获取学院所做过的项目及项目带头人信息
    projectlist = []
    with ClusterRpcProxy(CONFIG) as rpc:
        project = rpc.document.get_project(schoolName)
    for i in project:
        if i[0] in teacherlist:
            projectlist.append(i)
    projectlist.sort(key=lambda ele: ele[2], reverse=True)
    #项目带头人
    head_name = []
    #团队信息
    team = []

    if len(projectlist) != 0:
        for i in projectlist:
            head_name.append(i[0])
        for i in head_name[0:3]:
            head = i
            teaminfo = {}

            with ClusterRpcProxy(CONFIG) as rpc:
                a = rpc.document.get_title(head, institutionId)
                if a[1] and a[1] > 0:
                    head = head + "(院士)"
                if a[3] and a[3] > 0:
                    if ")" in head:
                        index1 = head.index(")")
                        head = head[0:index1] + "长江学者" + head[index1:]
                    else:
                        head = head + "(长江学者)"
                if a[2] and a[2] > 0:
                    if ")" in head:
                        index1 = head.index(")")
                        head = head[0:index1] + ",杰出青年" + head[index1:]
                    else:
                        head = head + "(杰出青年)"

            with ClusterRpcProxy(CONFIG) as rpc:
                # invention = rpc.document.get_invention(i)
                head_id = rpc.document.get_teacher_id(i, institutionId)
                paper = rpc.document.get_paper_info_2(head_id[0])
                honor = rpc.document.get_honor_2(head_id[0])

            # invention.sort(key=lambda ele: ele[1], reverse=True)
            # invention_info = []
            # for i in invention:
            #     invention_info.append(i[0])
            # invention_info = list(set(invention_info))[0:10]
            papername = []
            paperauthor = []
            member = []
            for i in paper:
                papername.append(i[1])
                paperauthor.append(i[0])
            for i in paperauthor:
                a = i.lstrip("[").rstrip("]").strip("{").split(",")
                for i in a:
                    if i.strip("{")[1:5] == "name":
                        member.append(i[i.index(":") + 2:len(i) - 1])
            member = list(set(member))
            if "(" in head and head[0:head.index("(")] in member:
                member.remove(head[0:head.index("(")])
            elif head in member:
                member.remove(head)
            if len(member) == 0:
                continue
            academician = []
            outyouth = []
            changjiang = []

            for i in member:
                for j in teacher:
                    if i == j[1]:
                        if j[2] and j[2] > 0:
                            academician.append(i)
                            if i in member:
                                member.remove(i)
                        if j[3] and j[3] > 0:
                            outyouth.append(i)
                            if i in member:
                                member.remove(i)
                        if j[4] and j[4] > 0:
                            changjiang.append(i)
                            if i in member:
                                member.remove(i)
            honorlist = []
            for i in honor:
                if i[-1:] == '奖':
                    honorlist.append(i)

            teaminfo['head_name'] = head
            teaminfo['academician_list'] = academician
            teaminfo['changjiang_list'] = changjiang
            teaminfo['outyouth_list'] = outyouth
            teaminfo['other_list'] = member
            teaminfo['team_direction'] = ""
            teaminfo['paper'] = papername
            teaminfo['invention'] = []
            teaminfo['award'] = honorlist
            team.append(teaminfo)
    # with ClusterRpcProxy(CONFIG) as rpc:
    #     rpc.document.createdocument(institution_info, team)
    session['institution_info'] = institution_info
    session['team'] = team
    return render_template("a.html",
                           institution_info=institution_info,
                           team=team)
コード例 #2
0
def sendPdfBytesForConversionToText():
    with ClusterRpcProxy(CONFIG) as rpc:
        result = rpc.industry_classifier.classify("some text")
    return result
コード例 #3
0
 def find_one_payment_status_by_error(self):
     with ClusterRpcProxy(self.config) as rpc:
         find_one_concept_by_code = rpc.crud.find_one_payment_status_by_error(
         )
         return find_one_concept_by_code['data']['allPaymentStatuses'][0]
コード例 #4
0
from nameko.standalone.rpc import ClusterRpcProxy

CONFIG = {'AMQP_URI': "amqp://*****:*****@localhost"}

with ClusterRpcProxy(CONFIG) as rpc:
    result = rpc.hello_microservice.hello("Micro-service Client")
    print(result)
コード例 #5
0
def sachima_rpc_reports(req):
    with ClusterRpcProxy(CONFIG) as rpc:
        # print(req)
        res = rpc.data.get_report(req.json)
        return res
コード例 #6
0
ファイル: helloServiceRpc.py プロジェクト: gmy007/MyDaliy
def compute():
    # 获取RPC代理对象
    with ClusterRpcProxy(CONFIG) as cluster_rpc:
        cluster_rpc.hello_service.hello()  # 调用rpc服务
コード例 #7
0
ファイル: test_rpc_proxy.py プロジェクト: simonclouds/nameko
def test_cluster_proxy(container_factory, rabbit_manager, rabbit_config):
    container = container_factory(FooService, rabbit_config)
    container.start()

    with ClusterRpcProxy(rabbit_config) as proxy:
        assert proxy.foobar.spam(ham=1) == 1
コード例 #8
0
 def __init__(self, service_name=None):
     self.rpc_cluster = ClusterRpcProxy(security_settings.AMQP_CONFIG)
     self.service_name = service_name
     self.rpc_proxy = self.rpc_cluster.start()
コード例 #9
0
ファイル: api.py プロジェクト: wb7777/yowsup-microservice
def send():
    logger = app.logger
    type = request.json.get('type')
    body = request.json.get('body')
    address = request.json.get('address')
    logger.info('Get message: %s,%s,%s' % (type, body, address))

    if not os.path.exists(os.path.dirname(STATUS_FILES_DIRECTORY)):
        try:
            os.makedirs(os.path.dirname(STATUS_FILES_DIRECTORY))
        except OSError as exc:  # Guard against race condition
            if exc.errno != errno.EEXIST:
                raise

    status_filename = STATUS_FILES_DIRECTORY + 'lock'

    # removing the file if it exists
    try:
        os.remove(status_filename)
    except:
        pass

    status = None
    try:
        with ClusterRpcProxy(CONFIG) as rpc:
            # asynchronously spawning and email notification
            rpc.yowsup.send(type, body, address)

        # trying to wait for success or fail
        timeouts = 0
        while status is None and timeouts < TIMEOUTS_NUMBER:
            timeouts += 1
            try:
                if os.path.isfile(status_filename):
                    status = 'success'

                if status is None:
                    sleep(TIMEOUT)
            except:
                pass
    except Exception as e:
        print('Error sending a message: {}'.format(str(e)))
    finally:
        try:
            os.remove(status_filename)
        except:
            pass

    if status == 'success':
        msg = "The message was successfully sent"
    elif status is None:
        # if the username is in environment variables
        _from = os.getenv('USERNAME')
        # if it is in config file
        if _from is None:
            # get current directory
            current_directory = os.path.dirname(
                os.path.abspath(inspect.getfile(inspect.currentframe())))
            # reading username from config
            full_config_file_path = '{}/{}'.format(current_directory,
                                                   CONFIG_FILE)
            stream = open(full_config_file_path, "r")
            doc = yaml.load(stream)
            _from = doc['YOWSUP_USERNAME']

        msg = '{{from: "{}", to:"{}", status: "undelivered"}}'.format(
            _from, address)

    return msg, 200
コード例 #10
0
 def delete(self, user_id):
     with ClusterRpcProxy(CONFIG) as rpc:
         rpc.userService.deleteUser(user_id)
     return {'message': 'Done'}
コード例 #11
0
 def delete(self, tape_id, user_id):
     with ClusterRpcProxy(CONFIG) as rpc:
         response = rpc.review_service.delete_review(user_id, tape_id)
         return(response['msg'], response['code'])
コード例 #12
0
 def put(self, user_id):
     with ClusterRpcProxy(CONFIG) as rpc:
         args = user_parser.parse_args()
         rpc.userService.updateUser(user_id, args)
     return {'message': 'Done'}
コード例 #13
0
 def get(self, user_id):
     with ClusterRpcProxy(CONFIG) as rpc:
         return rpc.userService.getUserByName(user_id)
コード例 #14
0
 def post(self):
     with ClusterRpcProxy(CONFIG) as rpc:
         args = user_parser.parse_args()
         rpc.userService.createNewUser(args)
     return {'message': 'Done'}
コード例 #15
0
ファイル: helloServiceRpc.py プロジェクト: gmy007/MyDaliy
# -*- coding:utf-8 -*-
from nameko.standalone.rpc import ClusterRpcProxy

CONFIG = {
    'AMQP_URI':
    "amqp://*****:*****@127.0.0.1"  # e.g. "pyamqp://*****:*****@localhost"
}


def compute():
    # 获取RPC代理对象
    with ClusterRpcProxy(CONFIG) as cluster_rpc:
        cluster_rpc.hello_service.hello()  # 调用rpc服务


def rpc_config():
    with ClusterRpcProxy(CONFIG) as cluster_rpc:
        print cluster_rpc.service_x.remote_method("hello")


if __name__ == '__main__':
    with ClusterRpcProxy(CONFIG) as cluster_rpc:
        print cluster_rpc.service_a.dispatching_method('message')
コード例 #16
0
def test_invalid_data():
    """Test to see if there is invalid (non string) data in the list
    """
    with ClusterRpcProxy(config) as cluster_rpc:
        assert cluster_rpc.compress_service.compress(
            [1, 'dog', 'cat', 'hamster']).get('status') == False
コード例 #17
0
ファイル: helloServiceRpc.py プロジェクト: gmy007/MyDaliy
def rpc_config():
    with ClusterRpcProxy(CONFIG) as cluster_rpc:
        print cluster_rpc.service_x.remote_method("hello")
コード例 #18
0
def test_decode():
    """Positive test to see that it decodes as expected"""
    with ClusterRpcProxy(config) as cluster_rpc:
        assert cluster_rpc.compress_service.decode('¸ñ').get('data') == 'dog'
コード例 #19
0
 def toxic_rpc_proxy(self, rabbit_config, toxiproxy):
     rabbit_config['AMQP_URI'] = toxiproxy.uri
     with ClusterRpcProxy(rabbit_config) as proxy:
         yield proxy
コード例 #20
0
def test_islist():
    """Test that will not break if it is not a list"""
    with ClusterRpcProxy(config) as cluster_rpc:
        assert cluster_rpc.compress_service.compress({
            'a': 3
        }).get('status') == False
コード例 #21
0
import os
import time
import requests
from datetime import datetime
from nameko.standalone.rpc import ClusterRpcProxy

url = "http://172.20.10.4:8000/picture"

config = {'AMQP_URI': os.environ.get('RABBIT_URL')}

while True:
    try:
        with ClusterRpcProxy(config) as cluster_rpc:
            print "taking picture"
            filename = str(datetime.now()).replace(" ", "")
            string = "fswebcam --no-banner -r 640x480 " + filename + ".jpg --skip 10"
            os.system(string)
            files = {"picture": open(filename + ".jpg", "rb")}
            response = requests.post(url, files=files)
            cluster_rpc.image_server.receive_image(filename)
            print "Sending to server"

            if response.ok:
                print "Upload complete"
                os.system("rm " + filename + ".jpg")
            else:
                print response.text
                print "Upload failed"

            print "sleeping"
            time.sleep(20)
コード例 #22
0
 def get(self):
     with ClusterRpcProxy(CONFIG) as rpc:
         return rpc.bookingsService.list()
コード例 #23
0
from nameko.standalone.rpc import ClusterRpcProxy

with ClusterRpcProxy({'AMQP_URI': "amqp://*****:*****@localhost"}) as rpc:
    print(rpc.serviceA.get_data())
    print(rpc.serviceA.get_data_from_serviceB())
コード例 #24
0
 def post(self):
     with ClusterRpcProxy(CONFIG) as rpc:
         args = booking_parser.parse_args()
         rpc.bookingsService.createNewBooking(args)
     return {'message': 'Done'}
コード例 #25
0
def test_event():
    with ClusterRpcProxy(CONFIG) as rpc:
        # asynchronously spawning the compute task
        for i in range(100):
            rpc.service_a.dispatching_method.call_async("payload test")
コード例 #26
0
 def put(self, booking_id):
     with ClusterRpcProxy(CONFIG) as rpc:
         args = booking_parser.parse_args()
         rpc.bookingsService.updateBooking(booking_id, args)
     return {'message': 'Done'}
コード例 #27
0
 def find_one_concept_by_code(self, code):
     with ClusterRpcProxy(self.config) as rpc:
         find_one_concept_by_code = rpc.crud.find_one_concept_by_code(code)
         return find_one_concept_by_code['data']['allPaymentConcepts'][0]
コード例 #28
0
 def delete(self, booking_id):
     with ClusterRpcProxy(CONFIG) as rpc:
         rpc.bookingsService.deleteBooking(booking_id)
     return {'message': 'Done'}
コード例 #29
0
 def update_necessity_concept_send_to_pay(self, id):
     with ClusterRpcProxy(self.config) as rpc:
         find_one_concept_by_code = rpc.crud.update_necessity_concept_send_to_pay(
             id)
         return find_one_concept_by_code['data']['updateNecessityConcept']
コード例 #30
0
def test():
    with ClusterRpcProxy(CONFIG) as rpc:
        t = rpc.test.test()
        print(t)
    return render_template("a.html", t=t)