Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------
- # celery.py
- ---------------------------
- import os
- from celery import Celery
- from celery.schedules import crontab # scheduler
- from dotenv import load_dotenv
- load_dotenv()
- os.environ.setdefault(
- "DJANGO_SETTINGS_MODULE", f"core.settings.{os.getenv('PROJ_ENVIROMENT')}"
- )
- app = Celery("core")
- app.config_from_object("django.conf:settings", namespace="CELERY")
- app.autodiscover_tasks(["jobsSchedule"])
- # scheduled task execution
- app.conf.beat_schedule = {
- "check-tips": {
- "task": "jobsSchedule.tasks.check_tips",
- "schedule": crontab(minute=0),
- },
- "scraping-task-daily-selenium": {
- "task": "jobsSchedule.tasks.getDailyMatches",
- "schedule": crontab(minute=0, hour=10),
- },
- }
- @app.task(bind=True)
- def debug_task(self):
- print("Request: {0!r}".format(self.request))
- ---------------------------
- #jobsSchedule/tasks.py
- ------------------------------
- from celery import shared_task
- from .dailyGetMatchOdds import GetDailyMatchData
- @shared_task
- def getDailyMatches():
- GetDailyMatchData()
- @shared_task
- def check_tips():
- from jobsSchedule import check_tip
- check_tip.run_task()
- ----------------------------------
- #jobsSchedule/check_tip.py
- -----------------------------------
- from datetime import date
- import requests
- from django.db.models import Count, Prefetch
- from flash.models.Tips import BtsTip, DcTip, HtftTip, MatchTip, OnextwoTip, OuTip
- from utils import send_check_msg
- today = date.today()
- fixture_url = "https://api-football-v1.p.rapidapi.com/v3/fixtures?date=" + str(today)
- # Her bir fixture_id ucun is_active=True olan
- all_is_active_tips = (
- MatchTip.objects.filter(is_active=True)
- .values("fixture_id")
- .distinct()
- .annotate(count=Count("fixture_id"))
- )
- # fixture_id listesi
- all_tips_fixture_list = [tip["fixture_id"] for tip in all_is_active_tips]
- # is_active=True count
- all_is_active_tips_count = MatchTip.objects.filter(is_active=True).count()
- headers = {
- "X-RapidAPI-Host": "",
- "X-RapidAPI-Key": "",
- }
- all_fixtures_response = requests.get(fixture_url, headers=headers).json()["response"]
- def check_match(all_fixtures_response):
- for fixture in all_fixtures_response:
- fixture_status = fixture["fixture"]["status"]["short"]
- if fixture_status == "FT":
- fixture_id = fixture["fixture"]["id"]
- match_score = fixture["score"]
- home_full_time_score = None
- away_full_time_score = None
- home_first_time_score = None
- away_first_time_score = None
- home_second_time_score = None
- away_second_time_score = None
- # full time
- match_fulltime = match_score["fulltime"]
- if match_fulltime["home"] is not None:
- home_full_time_score = int(match_fulltime["home"])
- if match_fulltime["away"] is not None:
- away_full_time_score = int(match_fulltime["away"])
- # first time
- match_halftime = match_score["halftime"]
- if match_halftime["home"] is not None:
- home_first_time_score = int(match_halftime["home"])
- if match_halftime["away"] is not None:
- away_first_time_score = int(match_halftime["away"])
- # second time
- if home_full_time_score is not None and home_first_time_score is not None:
- home_second_time_score = home_full_time_score - home_first_time_score
- if away_full_time_score is not None and away_first_time_score is not None:
- away_second_time_score = away_full_time_score - away_first_time_score
- if str(fixture_id) in all_tips_fixture_list:
- match_tips = MatchTip.objects.filter(fixture_id=fixture_id)
- match_tips = match_tips.prefetch_related(
- Prefetch(
- "tip_bts_tip",
- queryset=BtsTip.objects.filter(
- match_id__in=match_tips.values_list("id", flat=True)
- ).defer("created_at", "updated_at"),
- ),
- Prefetch(
- "tip_dc_tip",
- queryset=DcTip.objects.filter(
- match_id__in=match_tips.values_list("id", flat=True)
- ).defer("created_at", "updated_at"),
- ),
- Prefetch(
- "tip_htft_tip",
- queryset=HtftTip.objects.filter(
- match_id__in=match_tips.values_list("id", flat=True)
- ).defer("created_at", "updated_at"),
- ),
- Prefetch(
- "tip_onextwo_tip",
- queryset=OnextwoTip.objects.filter(
- match_id__in=match_tips.values_list("id", flat=True)
- ).defer("created_at", "updated_at"),
- ),
- Prefetch(
- "tip_ou_tip",
- queryset=OuTip.objects.filter(
- match_id__in=match_tips.values_list("id", flat=True)
- ).defer("created_at", "updated_at"),
- ),
- )
- check_odds(
- match_tips,
- home_first_time_score,
- away_first_time_score,
- home_second_time_score,
- away_second_time_score,
- home_full_time_score,
- away_full_time_score,
- )
- def check_odds(
- match_tips,
- home_first_time_score,
- away_first_time_score,
- home_second_time_score,
- away_second_time_score,
- home_full_time_score,
- away_full_time_score,
- ):
- for match_tip in match_tips:
- match_tip.home_first_time_score = home_first_time_score
- match_tip.away_first_time_score = away_first_time_score
- match_tip.home_second_time_score = home_second_time_score
- match_tip.away_second_time_score = away_second_time_score
- match_tip.home_full_time_score = home_full_time_score
- match_tip.away_full_time_score = away_full_time_score
- match_tip.save()
- if match_tip.tip_bts_tip.exists():
- for tip in match_tip.tip_bts_tip.all():
- # Full time
- if tip.half == "allmatch":
- # column - 1
- if (tip.column == "Yes") and (
- (home_full_time_score > 1) and (away_full_time_score > 1)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif (tip.column == "No") and (
- home_full_time_score == 0 and away_full_time_score == 0
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- elif tip.half == "firsthalf":
- # column - 1
- if (tip.column == "Yes") and (
- (home_full_time_score > 1) and (away_full_time_score > 1)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif (tip.column == "No") and (
- home_full_time_score == 0 and away_full_time_score == 0
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- elif tip.half == "secondhalf":
- # column - 1
- if (tip.column == "Yes") and (
- (home_full_time_score > 1) and (away_full_time_score > 1)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif (tip.column == "No") and (
- home_full_time_score == 0 and away_full_time_score == 0
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- if match_tip.tip_dc_tip.exists():
- for tip in match_tip.tip_dc_tip.all():
- # Full time
- if tip.half == "allmatch":
- # column - 1X
- if (tip.column == "1X") and (
- (home_full_time_score > away_full_time_score)
- or (home_full_time_score == away_full_time_score)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column -XX
- elif (tip.column == "XX") and (
- (home_full_time_score > away_full_time_score)
- or (away_full_time_score > home_full_time_score)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column -2X
- elif (tip.column == "2X") and (
- (away_full_time_score > home_full_time_score)
- or (home_full_time_score == away_full_time_score)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- elif tip.half == "firsthalf":
- # column - 1X
- if (tip.column == "1X") and (
- (home_full_time_score > away_full_time_score)
- or (home_full_time_score == away_full_time_score)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column -XX
- elif (tip.column == "XX") and (
- (home_full_time_score > away_full_time_score)
- or (away_full_time_score > home_full_time_score)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column -2X
- elif (tip.column == "2X") and (
- (away_full_time_score > home_full_time_score)
- or (home_full_time_score == away_full_time_score)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- elif tip.half == "secondhalf":
- # column - 1X
- if (tip.column == "1X") and (
- (home_full_time_score > away_full_time_score)
- or (home_full_time_score == away_full_time_score)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column -XX
- elif (tip.column == "XX") and (
- (home_full_time_score > away_full_time_score)
- or (away_full_time_score > home_full_time_score)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column -2X
- elif (tip.column == "2X") and (
- (away_full_time_score > home_full_time_score)
- or (home_full_time_score == away_full_time_score)
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- if match_tip.tip_onextwo_tip.exists():
- for tip in match_tip.tip_onextwo_tip.all():
- # Full time
- if tip.half == "allmatch":
- # column - 1
- if (tip.column == "1") and (
- home_full_time_score > away_full_time_score
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column - X
- elif (tip.column == "X") and (
- home_full_time_score == away_full_time_score
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column -2
- elif (tip.column == "2") and (
- home_full_time_score < away_full_time_score
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- # 1st half
- elif tip.half == "firsthalf":
- # column - 1
- if (tip.column == "1") and (
- home_full_time_score > away_full_time_score
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column - X
- elif (tip.column == "X") and (
- home_full_time_score == away_full_time_score
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column -2
- elif (tip.column == "2") and (
- home_full_time_score < away_full_time_score
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- # 2nd half
- elif tip.half == "secondhalf":
- # column - 1
- if (tip.column == "1") and (
- home_full_time_score > away_full_time_score
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column - X
- elif (tip.column == "X") and (
- home_full_time_score == away_full_time_score
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- # column -2
- elif (tip.column == "2") and (
- home_full_time_score < away_full_time_score
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- if match_tip.tip_ou_tip.exists():
- for tip in match_tip.tip_ou_tip.all():
- if tip.half == "allmatch":
- if "Over" in tip.column:
- if ("1.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("2.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("3.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("4.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- elif "Under" in tip.column:
- if ("1.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) <= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("2.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("3.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("4.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- elif tip.half == "firsthalf":
- if "Over" in tip.column:
- if ("1.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("2.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("3.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("4.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- elif "Under" in tip.column:
- if ("1.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) <= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("2.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("3.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("4.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- elif tip.half == "secondhalf":
- if "Over" in tip.column:
- if ("1.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("2.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("3.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("4.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- elif "Under" in tip.column:
- if ("1.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) <= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("2.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("3.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- elif ("4.5" in tip.column) and (
- (home_full_time_score + away_full_time_score) >= 2
- ):
- match_tip.is_correct = True
- match_tip.is_active = False
- match_tip.save()
- else:
- match_tip.is_correct = False
- match_tip.is_active = False
- match_tip.save()
- def run_task():
- check_match(all_fixtures_response)
- try:
- print("mail gonderiliri....")
- send_check_msg(all_is_active_tips_count)
- print("mail gonderildi")
- except Exception as e:
- print("xeta oldu", e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement