Пример #1
0
def explore(page=1):
    place = request.args.get('place')  #encoding error
    # lng = float(request.args.get('lng')) # can not be empty
    # lat = float(request.args.get('lat'))

    # in the beginning when we open home/explore, it shows all homes which is display_home
    display_home = Home.objects(cancel=False).order_by('-start_time').paginate(
        page=page, per_page=4)

    #homes = Home.objects(cancel=False).order_by('-start_time').paginate(page=page, per_page=4)

    try:
        lng = float(request.args.get('lng'))
        lat = float(request.args.get('lat'))
        print(lng, lat)
        homes = Home.objects(location__near=[lng, lat],
                             location__max_distance=10000,
                             cancel=False).order_by('-start_time').paginate(
                                 page=page, per_page=4)

        if homes: print("yes")
        print(homes)

        return render_template("home/explore.html",
                               homes=homes,
                               display_home=display_home,
                               place=place,
                               lng=lng,
                               lat=lat)
    except:

        return render_template('home/explore.html',
                               place=place,
                               display_home=display_home)
Пример #2
0
def create():
    form = BasicHomeForm()
    error = None
    if request.method == "POST" and form.validate():
        if form.end_datetime.data < form.start_datetime.data:
            error = "Available time must end after it starts!"
        if not error:
            user = User.objects.filter(email=session.get('email')).first()
            home = Home(name=form.name.data,
                        place=form.place.data,
                        location=[form.lng.data, form.lat.data],
                        start_time=form.start_datetime.data,
                        end_time=form.end_datetime.data,
                        description=form.description.data,
                        contact=form.contact.data,
                        host=user.id,
                        attendees=[user])
            # image_url = upload_image_file(request.files.get('photo'), 'party_photo', str(party.id))
            # if image_url:
            #   party.party_photo = image_url

            home.save()  #save to mdb
            return '{} created'.format(home.name)

    return render_template('home/create.html', form=form)
Пример #3
0
def home(request):
    if request.method == "GET":
        image = request.GET.get('image')
        question = request.GET.get('question')
        home = Home(image=image, question=question)
        home.save()
    return render(request, 'home.html')
Пример #4
0
def home(request):
    session = requests.session()
    req = session.get("https://www.basketball-reference.com/boxscores/")
    doc = BeautifulSoup(req.content, 'html.parser')
    winners = re.sub("\\<.*?\\> ?", "", str(doc.findAll('tr', {"class": "winner"})))
    winners = re.sub("OT", "", re.sub("\n", " ", re.sub("Final", "", winners)))
    winners = winners.replace('[','').replace(']','')
    wpts = [int(x) for x in winners.split() if x.isdigit()]
    winners = [x.strip() for x in ''.join([i for i in winners if not i.isdigit()]).split(',') if not x.isdigit()]
    losers = re.sub("\\<.*?\\> ?", "", str(doc.findAll('tr', {"class": "loser"})))
    losers = re.sub("OT", "", re.sub("\n", " ", re.sub("Final", "", losers)))
    losers = losers.replace('[','').replace(']','')
    lpts = [int(x) for x in losers.split() if x.isdigit()]
    losers = [x.strip() for x in ''.join([i for i in losers if not i.isdigit()]).split(',') if not x.isdigit()]
    for i in range(len(winners)):
        if (i == 0) & (Home.objects.exists()):
            obj = model_to_dict(Home.objects.all()[0])
            if ((winners[i] == obj['winner']) & (losers[i] == obj['loser']) & (wpts[i] == obj['wpts']) & (lpts[i] == obj['lpts'])):
                break
            else:
                Home.objects.all().delete()
        entry = Home(winner=winners[i], wpts=wpts[i], loser=losers[i], lpts=lpts[i])
        if not Home.objects.filter(winner=winners[i], wpts=wpts[i], loser=losers[i], lpts=lpts[i]).exists():
            entry.save()
    home = Home.objects.all()
    context = {
        'home': home
    }
    return render(request, 'home.html', context)
Пример #5
0
def home(request):
    if request.method =="POST":
        title = request.POST['title']
        desc = request.POST['desc']
        ins = Home(title=title,desc=desc)
        ins.save()
        print("done for the data")
    return render(request,'home.html')
Пример #6
0
    def handle(self, *args, **options):

        if not Home.objects.all().exists():
            root = Page.objects.get(pk=2)
            my_home = Home(title='Welcome to Tennis Block',
                           intro="<b>We can schedule your tennis life</b>",
                           slug='home')
            root.add_child(instance=my_home)
            my_home.save_revision().publish()
def home(request):
    if request.method == "POST":
        name = request.POST['name']
        email = request.POST['email']
        subject = request.POST['subject']
        message = request.POST['message']
        ins = Home(name=name, email=email, subject1=subject, message1=message)
        ins.save()
        messages.success(request, 'YOUR response has been recived')
        print("done for the data")
    return render(request, 'index.html')
Пример #8
0
def home_text(request):
    default_response = Response(HomeSerializer(Home(), many=False).data)
    if request.method != 'GET':
        return default_response
    try:
        text = Home.objects.get()
        serializer = HomeSerializer(text, many=False)
        return Response(serializer.data)
    except ObjectDoesNotExist:
        return default_response
Пример #9
0
def add_games(request):
    next_ = request.GET.get('next')
    next_post = request.POST.get('next')
    redirect_path = next_ or next_post or None
    available_list = Home.objects.all().values_list('match_date')
    home_url = 'https://www.soccerway.com'
    perc = 0.7
    analyser_link1 = link_analyser(home_url)
    for item in analyser_link1.findAll('th', {'class': regex_gen('competition-link')}):
        extracted_link1 = extract_link(item)
        for each_link in extracted_link1:
            analyser_link2 = link_analyser(home_url+each_link)
            for item2 in analyser_link2.findAll('table', {'class': 'matches'}):
                for item3 in item2.findAll('tr', {'class': regex_gen('match no-date-repetition')}):
                    for item4 in item3.findAll('td', {'class': 'score-time status'}):
                        extracted_link2 = extract_link(item4)
                        extracted_text1 = extract_text(item4,  'span', 'timestamp')
                        for evt_time, item_url in zip(extracted_text1, extracted_link2):
                            evt_in_range, _, evt_date_time = extract_date(item_url, evt_time)
                            if not evt_date_time in available_list:
                                if evt_in_range and item_url and evt_time:
                                    team_info = {}
                                    for item5 in item3.findAll('td', {'class': 'team team-a'}):
                                        for home_team in extract_text(item5):
                                            team_info['home_team'] = home_team
                                    for item6 in item3.findAll('td', {'class': 'team team-b'}):
                                        for away_team in extract_text(item6):
                                            team_info['away_team'] = away_team
                                    team_info['match_date'] = make_aware(evt_date_time)
                                    team_info['soccerway_url'] = home_url+item_url

                                    analyser_link3 = link_analyser(home_url+item_url)
                                    total_teams = 0
                                    psn = 0
                                    name = None
                                    position_of = 0
                                    uib_data = 0
                                    for item16 in analyser_link3.findAll('div', {'class': 'yui-b'}):
                                        if uib_data == 1:
                                            for item17 in item16.findAll('h2'):
                                                league_link1 = home_url + extract_link(item17)[0]
                                            for item7 in item16.findAll('table', {'class': 'leaguetable sortable table'}):
                                                for item8 in analyser_link3.findAll('div', {'class': 'block_match_info real-content clearfix'}):
                                                    for item9 in item8.findAll('div', {'class': 'details clearfix'}):
                                                        league_link2 = home_url + extract_link(item9)[0]
                                                        if SequenceMatcher(a=league_link1, b=league_link2).ratio() > 0.9:
                                                            league_link = league_link2
                                                        else:
                                                            league_link = league_link1
                                                        ana_link = link_analyser(league_link)
                                                        for item10 in ana_link.findAll('table', {'class': 'leaguetable sortable table detailed-table'}):
                                                            for _ in item10.findAll('tr', {'class':  regex_gen('team_rank')}):
                                                                total_teams += 1
                                                        break
                                                for item12 in item7.findAll('tr', {'class': regex_gen('highlight')}):
                                                    for item13 in item12.findAll('td', {'class': regex_gen('rank')}):
                                                        position_of = int(item13.string)
                                                    for team_name in extract_text(item12):
                                                        name = team_name
                                                    smtc = SequenceMatcher(a=home_team, b=name).ratio()
                                                    try:
                                                        if smtc > 0.5:
                                                            psn -= position_of
                                                        else:
                                                            psn = position_of
                                                    except (TypeError, Exception):
                                                        pass
                                            try:
                                                total_teams -= 1
                                                score = psn/total_teams
                                            except (ZeroDivisionError, TypeError):
                                                score = 0
                                            if score >= perc:
                                                team_info['p_table_score'] = 'Home'
                                            elif score <= -perc:
                                                team_info['p_table_score'] = 'Away'
                                            else:
                                                team_info['p_table_score'] = None
                                            abs_score = abs(int(score*100))
                                            team_info['table_score'] = abs_score
                                            if team_info:
                                                hm_aw = ('left', 'right')
                                                wld_percentage = perc*0.7
                                                psn_gap = None
                                                for home_away in hm_aw:
                                                    for item14 in item8.findAll('div', {'class': 'container ' + home_away}):
                                                        for item15 in item14.findAll('div', {'class': 'form clearfix'}):
                                                            extracted_text2 = extract_text(item15)
                                                            lap = 0
                                                            total_score = 0
                                                            for outcome in extracted_text2:
                                                                lap += 1
                                                                if outcome == 'W':
                                                                    total_score += 16 - lap
                                                                if outcome == 'D':
                                                                    total_score += 5 + lap
                                                                if outcome == 'L':
                                                                    total_score += lap
                                                                if lap == 5:
                                                                    lap = 0
                                                    if total_score >= 0:
                                                        wdl_score = total_score - 15
                                                    else:
                                                        wdl_score = total_score + 15
                                                    if psn_gap:
                                                        psn_gap -= wdl_score
                                                    else:
                                                        psn_gap = wdl_score
                                                try:
                                                    wl_score = psn_gap/50
                                                except (ZeroDivisionError, TypeError):
                                                    wl_score = 0
                                                if wl_score >= wld_percentage:
                                                    team_info['p_last_five_score'] = 'Home'
                                                elif wl_score <= -wld_percentage:
                                                    team_info['p_last_five_score'] = 'Away'
                                                else:
                                                    team_info['p_last_five_score'] = None
                                                abs_wl_score = abs(int(wl_score*100))
                                                team_info['last_five_score'] = abs_wl_score
                                                if team_info:
                                                    bet_link = betin(home_team)
                                                    bet_link2 = betin(away_team)
                                            if bet_link:
                                                team_info['betin_url'] = bet_link
                                            else:
                                                team_info['betin_url'] = bet_link2
                                            try:
                                                new_Home = Home(**team_info)
                                                new_Home.save()
                                                print('saved')
                                            except Exception:
                                                pass
                                        uib_data += 1

    if is_safe_url(redirect_path, request.get_host()):
        return redirect(redirect_path)
    return redirect('home_page:index')
Пример #10
0
def create_home(owner, home_id):
    avatar = default_home_pic
    home = Home(owner=owner, home_id=home_id, avatar=avatar)
    home.save()