{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6405f0ad-a363-4d36-a808-6f778c7b8c65",
   "metadata": {},
   "source": [
    "## 1. start here, run this cell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1a332d6f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "b5e83551f1084e628a2bcdcf87665185",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Dropdown(description='Select an option:', options=('2024-05-27,Finnish Division 1(芬蘭超級聯賽),Lahti(拉迪) vs SJK Sei…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import os,sys,json\n",
    "from pprint import pprint\n",
    "import nest_asyncio\n",
    "import asyncio\n",
    "import ipywidgets as widgets\n",
    "\n",
    "from api_footylogic_com.match.statistics.MarketsInfo import getMarketsInfoJson\n",
    "from api_footylogic_com.match.h2h.RecentformInformation import getRecentformInformationJson\n",
    "from api_footylogic_com.tournament.Standings import getStandingsJson\n",
    "from api_footylogic_com.tournament.Competitions import getCompetitionsJson, lookupCompetitionId\n",
    "from api_footylogic_com.match.h2h.Banner import getBannerJson, getTeams, getCompetitionName\n",
    "from api_footylogic_com.match.seasonalstats.DropdownFilters import getDropdownFilters\n",
    "from bet_hkjc_com.football.getJSON import getMatchesJson, getMatchesList\n",
    "\n",
    "from utils.Statistics import getTopBottomWinningAndLoseing\n",
    "from utils.WriteExcel import writeExcel\n",
    "from utils.GetScreenshot import getScreenshot\n",
    "from utils.reports import genExcelReport\n",
    "from utils.getDropdownMenu import genMatchList\n",
    "\n",
    "[options, matches_list] = genMatchList()\n",
    "dropdown = widgets.Dropdown(options=options, description='Select an option:')\n",
    "display(dropdown)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8309647-791d-4d6b-bb01-4c417c46b13c",
   "metadata": {},
   "source": [
    "## 2. select matches and run below cell"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "98987f47-b2af-4932-9f8d-f0a47dca1c10",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['50019599', '50026115']\n",
      "generate report for 2024-03-23,Spanish Division 2(西班牙乙組聯賽),Alcorcon(艾高干) vs Oviedo(奧維多)\n"
     ]
    }
   ],
   "source": [
    "# generate_report_key = dropdown.value\n",
    "generate_report_key = '2024-03-23,Spanish Division 2(西班牙乙組聯賽),Alcorcon(艾高干) vs Oviedo(奧維多)'\n",
    "\n",
    "report_filename= generate_report_key.replace(',','_').replace(' ','_') +'.xlsx'\n",
    "[tournamentID,matchID] = matches_list[generate_report_key]\n",
    "pprint([tournamentID,matchID])\n",
    "\n",
    "# print('generate report for '+ generate_report_key)\n",
    "print('generate report for '+ generate_report_key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6a31f956-0ff4-4341-8549-8421da70ab04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "https://footylogic.com/en/matchcenter/0/50019599/50026115/bmstatistics\n",
      "https://footylogic.com/en/matchcenter/0/50019599/50026115/bmrecentforms\n",
      "https://footylogic.com/en/tournament/league/50019599/standings\n",
      "/app/notebook/_images/bmstatistics.png\n",
      "/app/notebook/_images/bmrecentforms.png\n",
      "/app/notebook/_images/standings.png\n",
      "reports.py: done...\n"
     ]
    }
   ],
   "source": [
    "genExcelReport(tournamentID, matchID, report_filename)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "772987b4-0d77-4ed0-a396-b0b685608930",
   "metadata": {},
   "source": [
    "## 3. grab the report in _output directory"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3c46d722-0715-4aaf-8b4f-d4163ad88742",
   "metadata": {},
   "source": [
    "### end for phase one"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4545183e-5e9d-4663-b0a3-08348d56a845",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "07:02:43.817861\n",
      "2024-05-27,Finnish Division 1(芬蘭超級聯賽),Lahti(拉迪) vs SJK Seinajoki(施拿祖基)\n",
      "working on 0/13 , 2024-05-27,Finnish Division 1(芬蘭超級聯賽),Lahti(拉迪) vs SJK Seinajoki(施拿祖基)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "2024-05-27,Finnish Division 1(芬蘭超級聯賽),VPS Vaasa(VPS華沙) vs Inter Turku(國際杜古)\n",
      "working on 1/13 , 2024-05-27,Finnish Division 1(芬蘭超級聯賽),VPS Vaasa(VPS華沙) vs Inter Turku(國際杜古)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "2024-05-28,Swedish Division 1(瑞典超級聯賽),Norrkoping(諾高平) vs Varnamo(華納莫)\n",
      "working on 2/13 , 2024-05-28,Swedish Division 1(瑞典超級聯賽),Norrkoping(諾高平) vs Varnamo(華納莫)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "2024-05-28,Swedish Division 1(瑞典超級聯賽),AIK Solna(AIK蘇納) vs Goteborg(哥登堡)\n",
      "working on 3/13 , 2024-05-28,Swedish Division 1(瑞典超級聯賽),AIK Solna(AIK蘇納) vs Goteborg(哥登堡)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "https://footylogic.com/en/matchcenter/0/50027252/50029417/bmstatistics\n",
      "https://footylogic.com/en/matchcenter/0/50027252/50029417/bmrecentforms\n",
      "https://footylogic.com/en/tournament/league/50027252/standings\n",
      "2024-05-28,German Division 1(德國甲組聯賽),Dusseldorf(杜塞爾多夫) vs Bochum(波琴)\n",
      "working on 4/13 , 2024-05-28,German Division 1(德國甲組聯賽),Dusseldorf(杜塞爾多夫) vs Bochum(波琴)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "https://footylogic.com/en/matchcenter/0/50016467/50029521/bmstatistics\n",
      "https://footylogic.com/en/matchcenter/0/50016467/50029521/bmrecentforms\n",
      "https://footylogic.com/en/tournament/league/50016467/standings\n",
      "2024-05-28,Argentine Division 1(阿根廷甲組聯賽),Union Santa Fe(聖達菲聯) vs Barracas Central(巴拉卡斯中央)\n",
      "working on 5/13 , 2024-05-28,Argentine Division 1(阿根廷甲組聯賽),Union Santa Fe(聖達菲聯) vs Barracas Central(巴拉卡斯中央)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "https://footylogic.com/en/matchcenter/0/50029135/50029547/bmstatistics\n",
      "https://footylogic.com/en/matchcenter/0/50029135/50029547/bmrecentforms\n",
      "https://footylogic.com/en/tournament/league/50029135/standings\n",
      "2024-05-28,Argentine Division 1(阿根廷甲組聯賽),Atletico Tucuman(圖庫曼體育會) vs CA Platense(CA普拉坦斯)\n",
      "working on 6/13 , 2024-05-28,Argentine Division 1(阿根廷甲組聯賽),Atletico Tucuman(圖庫曼體育會) vs CA Platense(CA普拉坦斯)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "https://footylogic.com/en/matchcenter/0/50029135/50029560/bmstatistics\n",
      "https://footylogic.com/en/matchcenter/0/50029135/50029560/bmrecentforms\n",
      "https://footylogic.com/en/tournament/league/50029135/standings\n",
      "2024-05-28,Korean Division 1(南韓職業聯賽),Gimcheon Sangmu(金泉尚武) vs FC Seoul(FC首爾)\n",
      "working on 7/13 , 2024-05-28,Korean Division 1(南韓職業聯賽),Gimcheon Sangmu(金泉尚武) vs FC Seoul(FC首爾)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "https://footylogic.com/en/matchcenter/0/50026040/50029439/bmstatistics\n",
      "https://footylogic.com/en/matchcenter/0/50026040/50029439/bmrecentforms\n",
      "https://footylogic.com/en/tournament/league/50026040/standings\n",
      "2024-05-28,Korean Division 1(南韓職業聯賽),Gwangju FC(FC光州) vs Pohang Steelers(浦項制鐵)\n",
      "working on 8/13 , 2024-05-28,Korean Division 1(南韓職業聯賽),Gwangju FC(FC光州) vs Pohang Steelers(浦項制鐵)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "https://footylogic.com/en/matchcenter/0/50026040/50029440/bmstatistics\n",
      "https://footylogic.com/en/matchcenter/0/50026040/50029440/bmrecentforms\n",
      "https://footylogic.com/en/tournament/league/50026040/standings\n",
      "2024-05-29,German Division 2(德國乙組聯賽),Wehen(韋恩) vs Jahn Regensburg(雷根斯堡)\n",
      "working on 9/13 , 2024-05-29,German Division 2(德國乙組聯賽),Wehen(韋恩) vs Jahn Regensburg(雷根斯堡)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "https://footylogic.com/en/matchcenter/0/50016660/50029643/bmstatistics\n",
      "https://footylogic.com/en/matchcenter/0/50016660/50029643/bmrecentforms\n",
      "https://footylogic.com/en/tournament/league/50016660/standings\n",
      "2024-05-29,Japanese Division 1(日本職業聯賽),Yokohama F.Marinos(橫濱水手) vs Kashiwa Reysol(柏雷素爾)\n",
      "working on 10/13 , 2024-05-29,Japanese Division 1(日本職業聯賽),Yokohama F.Marinos(橫濱水手) vs Kashiwa Reysol(柏雷素爾)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "https://footylogic.com/en/matchcenter/0/50025768/50029414/bmstatistics\n",
      "https://footylogic.com/en/matchcenter/0/50025768/50029414/bmrecentforms\n",
      "https://footylogic.com/en/tournament/league/50025768/standings\n",
      "2024-05-30,UE Conference(歐洲協會聯賽),Olympiakos(奧林比亞高斯) vs Fiorentina(費倫天拿)\n",
      "working on 11/13 , 2024-05-30,UE Conference(歐洲協會聯賽),Olympiakos(奧林比亞高斯) vs Fiorentina(費倫天拿)\n",
      "Banner.py: get banner json done\n",
      "MarketsInfo.py: getMarketsInfoJson done\n",
      "DropdownFilters.py: get getDropdownFilters json done\n",
      "Options.py: get options done\n",
      "Standings.py: get standings done\n",
      "2024-06-02,UE Champions(歐洲聯賽冠軍盃),Dortmund(多蒙特) vs Real Madrid(皇家馬德里)\n",
      "07:03:09.214254\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "print(datetime.now().time())\n",
    "\n",
    "target_date = '2024-05'\n",
    "\n",
    "for i in range(0, len(options)):\n",
    "    try:\n",
    "        option = options[i]\n",
    "        print(option)\n",
    "        if (option.index(target_date) > -1):\n",
    "            print('working on '+str(i)+'/'+str(len(options))+' , '+option)\n",
    "            [tournamentID,matchID] = matches_list[option]\n",
    "            report_filename= option.replace(',','_').replace(' ','_') +'.xlsx'\n",
    "            genExcelReport(tournamentID, matchID, report_filename)\n",
    "    except Exception as e:\n",
    "        pass\n",
    "\n",
    "print(datetime.now().time())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e1bb1c6-6b4b-4c4b-ad93-5192fdd7faf0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
