Example #1
0
def handle_my_custom_event(json, methods=['GET', 'POST']):
    print('received my event: ' + str(json))
    print ('user id is ', current_user.gender)
    if 'data' in json.keys():
        print(str(json))
    response_data = {}

    if 'message' in json.keys():
        message = json['message']
        response = chatbot.get_answer(message)
        products = []
        degree = response[1]
        print('degree is', degree)
        name = response[2]
        print('in app', name)

        product_list = []
        print('degree', degree)

        if degree == 'category':
            products = ponyDB.get_product_by_category(product_category=name, user_gender=current_user.gender)
        elif degree == 'subcategory':
            products = ponyDB.get_product_by_subcategory(product_subcategory=name, user_gender=current_user.gender)
        elif degree == 'brand':
            subcategory = response[3]
            print('getting products by brand')
            products = ponyDB.get_product_by_brand(product_subcategory=subcategory, product_brand=name, user_gender=current_user.gender)
        elif degree == 'general_answer':
            print('len name', len(name))
            for n in name:
                print('n is '+n)
                products += ponyDB.get_product_by_subcategory(product_subcategory=str(n), user_gender=current_user.gender)
        elif degree == 'price_answer':
                products = ponyDB.get_product_by_price(price=name)

        else:
            products = ponyDB.get_products()

        if products is not None:
            product_list = products

        response_data['response'] = response[0]
        response_data['products'] = product_list

    socketio.emit('my response', response_data, callback=messageReceived)
Example #2
0
def register():
    json = request.get_json()
    git_api_key = json['git_api_key']
    docker_hub_u = json['docker_hub_u']
    docker_hub_p = json['docker_hub_p']

    gcloud_project = json['gcloud_config']['project']
    gcloud_instance = json['gcloud_config']['instance']
    gcloud_zone = json['gcloud_config']['zone']
    gcloud_user = json['gcloud_config']['user']

    repository_name = json['repository_name']
    print("oi!")
    if bws.__contains__(repository_name) is False:
        hook_id = None
        if json.__contains__('hook_id'):
            hook_id = json['hook_id']

        print("Creating builder")
        bw = BuilderWrapper(git_api_key=git_api_key,
                            docker_hub_u=docker_hub_u,
                            docker_hub_p=docker_hub_p,
                            repository_name=repository_name,
                            hook_id=hook_id)

        print("HOOKs: " + str(bw.project.repo.get_hooks().get_page(0)))
        if "clear_hooks" in json.keys():
            print("DELETING HOOKS")
            hooks = bw.project.repo.get_hooks().get_page(0)
            for h in hooks:
                h.delete()
                print("old hoook deleted!")


#        bw.project.repo.get_hook(14430897).delete()
#        bw.project.repo.get_hook(14452288).delete()
#        bw.project.repo.get_hook(14452038).delete()
#        bw.project.repo.get_hook(14429077).delete()
        print("Builder created!")

        bw.gcloud_config = GCloudConfig(instance=gcloud_instance,
                                        project=gcloud_project,
                                        zone=gcloud_zone,
                                        user=gcloud_user)

        OutputGenerator.init_project_output_folder(bw)

        bw.print_config()
        bws[repository_name] = bw

        print("repo hook: " + str(bw.project.hook))

        return 'Builder created with success'
    else:
        return "Builder already exists"
Example #3
0
def hello():
    # for i in request:
    #     print i
    # print request["asd"]
    if request.headers['Content-Type'] == 'application/json':
        json = request.json
        # print "HUI"
        # print json
        # for j in json:
        #     print j
        # print json["choices"]['0']
        # print json["student_id"]
        team = Team()
        if "student_id" in json.keys() and "team_letter" in json.keys():
            team.student_id = json["student_id"]
            team.team_letter = json["team_letter"]
            team.choice1 = json["choices"]['0']
            team.choice2 = json["choices"]['1']
            team.choice3 = json["choices"]['2']
            team.choice4 = json["choices"]['3']
            team.choice5 = json["choices"]['4']
            team.choice6 = json["choices"]['5']
            team.choice7 = json["choices"]['6']
            team.choice8 = json["choices"]['7']
            # print team.student_id
            # print team.team_letter
            # print team.choice1
            # print team.choice2
            # print team.choice3
            # print team.choice4
            # print team.choice5
            # print team.choice6
            # print team.choice7
            # print team.choice8
            db.session.add(team)
            db.session.commit()

            # print json['0']
        return "JSON Message: "
    return "ASDASD"
Example #4
0
def is_valid_sell_data_request(json):
    if not isinstance(json, dict):
        return False
    if set(json.keys()) != {"mac", "tagId"}:
        return False
    return True
Example #5
0
def is_valid_confirm_user_request(json):
    if not isinstance(json, dict):
        return False
    if set(json.keys()) != {"email", "key"}:
        return False
    return True
Example #6
0
def is_valid_vote_request(json):
    if not isinstance(json, dict):
        return False
    if set(json.keys()) != {"mac", "tagId", "isPositive", "timestamp"}:
        return False
    return True
Example #7
0
 def load(self, json):
     jsonAttr = list(json.keys())
     for attr in vars(self):
         if attr in jsonAttr:
             self.__setattr__(attr, json[attr])
def is_valid_sell_data_request(json):
    if not isinstance(json, dict):
        return False
    if set(json.keys()) != {"mac", "tagId"}:
        return False
    return True
def is_valid_confirm_user_request(json):
    if not isinstance(json, dict):
        return False
    if set(json.keys()) != {"email", "key"}:
        return False
    return True
Example #10
0
def is_valid_vote_request(json):
    if not isinstance(json, dict):
        return False
    if set(json.keys()) != {"mac", "tagId", "isPositive", "timestamp"}:
        return False
    return True
def check(json):
    k = json.keys()
    return ('id' in k and 'email' in k and "hashtags" in k and "mentions" in k
            and "startDate" in k and "finDate" in k)
Example #12
0
def add_members_to_petition(json, petition_group_id):
    member_emails = [
        json[key] for key in json.keys() if 'custom_email_' in key
    ]
    return db.add_members(member_emails, petition_group_id)