Karl Hudgell 1 год назад
Родитель
Сommit
31fe69d709
5 измененных файлов с 46 добавлено и 26 удалено
  1. 10 0
      base_table.csv
  2. 0 13
      fixtures.csv
  3. 12 12
      fixtures.ics
  4. 20 1
      main.py
  5. 4 0
      results.csv

+ 10 - 0
base_table.csv

@@ -0,0 +1,10 @@
+POS,Team,P,W,D,L,PTS,Unnamed: 7
+1.0,Farnham Town Panthers,6.0,5.0,0.0,1.0,15.0,
+2.0,Aldershot B&G Lions,5.0,4.0,0.0,1.0,12.0,
+3.0,Down Grange Pumas,3.0,3.0,0.0,0.0,9.0,
+4.0,Fernhurst Sports Terriers,4.0,3.0,0.0,1.0,9.0,
+5.0,Tongham U12,5.0,2.0,1.0,2.0,7.0,
+6.0,Petersfield Town Revolution,5.0,1.0,0.0,4.0,3.0,
+7.0,Mytchett Athletic Hawks,7.0,1.0,0.0,6.0,3.0,
+8.0,Curley Park Rangers Mambas,5.0,0.0,1.0,4.0,1.0,
+,,,,,,,

+ 0 - 13
fixtures.csv

@@ -1,13 +0,0 @@
-Type,Date / Time,Home Team,Home Team.1,Unnamed: 4,Away Team,Away Team.1,Venue,Competition,Status / Notes
-Cup,20/01/24 08:00,Beacon Hill U12 Rockets,,VS,,Down Grange U12 Pumas,HINDHEAD PLAYING FIELDS (HINDHEAD CC) 1,U12 League Vase(No Deliberate Heading)_2023 - 2024,
-L,27/01/24 08:00,Down Grange U12 Pumas,,VS,,Mytchett Athletic U12 Hawks,DOWN GRANGE SPORTS COMPLEX #2,U12 Division 8 - No Heading Trial,
-L,03/02/24 08:00,Fernhurst Sports U12 Terriers,,VS,,Down Grange U12 Pumas,FERNHURST RECREATION GROUND,U12 Division 8 - No Heading Trial,
-L,10/02/24 08:00,Down Grange U12 Pumas,,VS,,Aldershot B&G U12 Lions,DOWN GRANGE SPORTS COMPLEX #2,U12 Division 8 - No Heading Trial,
-L,17/02/24 08:00,Down Grange U12 Pumas,,VS,,Petersfield Town U12 Revolution,DOWN GRANGE SPORTS COMPLEX #2,U12 Division 8 - No Heading Trial,Match Notes:  Double Header - Matches to be played at Down Grange's ground
-L,17/02/24 08:00,Petersfield Town U12 Revolution,,VS,,Down Grange U12 Pumas,DOWN GRANGE SPORTS COMPLEX #2,U12 Division 8 - No Heading Trial,Match Notes:  Double Header - Matches to be played at Down Grange's ground
-L,24/02/24 08:00,Curley Park Rangers U12 Mambas,,VS,,Down Grange U12 Pumas,LIGHTWATER RECREATION GROUND,U12 Division 8 - No Heading Trial,
-L,02/03/24 08:00,Tongham U12,,VS,,Down Grange U12 Pumas,POYLE ROAD RECREATION GROUND #2,U12 Division 8 - No Heading Trial,
-L,09/03/24 08:00,Down Grange U12 Pumas,,VS,,Farnham Town U12 Panthers,DOWN GRANGE SPORTS COMPLEX #2,U12 Division 8 - No Heading Trial,
-L,16/03/24 08:00,Down Grange U12 Pumas,,VS,,Fernhurst Sports U12 Terriers,DOWN GRANGE SPORTS COMPLEX #2,U12 Division 8 - No Heading Trial,
-L,06/04/24 08:00,Down Grange U12 Pumas,,VS,,Tongham U12,DOWN GRANGE SPORTS COMPLEX #2,U12 Division 8 - No Heading Trial,
-L,23/04/24 08:00,Down Grange U12 Pumas,,VS,,Curley Park Rangers U12 Mambas,DOWN GRANGE SPORTS COMPLEX #2,U12 Division 8 - No Heading Trial,

+ 12 - 12
fixtures.ics

@@ -6,7 +6,7 @@ SUMMARY:(Cup) Beacon Hill Rockets VS Down Grange Pumas
 DTSTART:20240120T093000
 DTEND:20240120T113000
 DTSTAMP:20240120T093000Z
-UID:f64cfab2-2764-4602-a8e0-15391f745784
+UID:a3699b87-8020-486e-9679-f3d547f94070
 DESCRIPTION:Arrive by - 2024-01-20 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&
@@ -19,7 +19,7 @@ SUMMARY:(League) Down Grange Pumas (3rd) VS Mytchett Athletic Hawks (7th)
 DTSTART:20240127T093000
 DTEND:20240127T113000
 DTSTAMP:20240127T093000Z
-UID:5e25f206-4359-40a7-9f73-598d59781042
+UID:bc30689f-ed88-46ec-8fd4-9764a3a58519
 DESCRIPTION:Arrive by - 2024-01-27 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&
@@ -33,7 +33,7 @@ SUMMARY:(League) Fernhurst Sports Terriers (4th) VS Down Grange Pumas (3rd
 DTSTART:20240203T093000
 DTEND:20240203T113000
 DTSTAMP:20240203T093000Z
-UID:6c3a343e-006b-4260-b0f2-c75147f7a823
+UID:25d6faa9-5b89-494b-b93b-4cc9e585cd1c
 DESCRIPTION:Arrive by - 2024-02-03 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&
@@ -46,7 +46,7 @@ SUMMARY:(League) Down Grange Pumas (3rd) VS Aldershot B&G Lions (2nd)
 DTSTART:20240210T093000
 DTEND:20240210T113000
 DTSTAMP:20240210T093000Z
-UID:1c6d7910-76a1-4ddb-9ce1-29bca7efec7c
+UID:962e93ff-ff1d-40a7-b35e-5f4297a5d962
 DESCRIPTION:Arrive by - 2024-02-10 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&
@@ -60,7 +60,7 @@ SUMMARY:(League) Down Grange Pumas (3rd) VS Petersfield Town Revolution (6
 DTSTART:20240217T093000
 DTEND:20240217T113000
 DTSTAMP:20240217T093000Z
-UID:d7e932b0-5430-437a-8d9f-71e787b51093
+UID:470e4d35-59fd-4de7-8001-a5cca3ad2743
 DESCRIPTION:Arrive by - 2024-02-17 09:00:00\nMatch Notes:  Double Header -
   Matches to be played at Down Grange's ground\n Table - \nhttps://fulltime
  .thefa.com/table.html?selectedSeason=19010414&selectedDivision=165601607&f
@@ -75,7 +75,7 @@ SUMMARY:(League) Petersfield Town Revolution (6th) VS Down Grange Pumas (3
 DTSTART:20240217T093000
 DTEND:20240217T113000
 DTSTAMP:20240217T093000Z
-UID:18ef51f7-bbcb-4e45-8a9e-50b9e7f725b5
+UID:c69f08aa-7531-4efe-af92-7d51489a4c47
 DESCRIPTION:Arrive by - 2024-02-17 09:00:00\nMatch Notes:  Double Header -
   Matches to be played at Down Grange's ground\n Table - \nhttps://fulltime
  .thefa.com/table.html?selectedSeason=19010414&selectedDivision=165601607&f
@@ -90,7 +90,7 @@ SUMMARY:(League) Curley Park Rangers Mambas (8th) VS Down Grange Pumas (3r
 DTSTART:20240224T093000
 DTEND:20240224T113000
 DTSTAMP:20240224T093000Z
-UID:98f57724-0fd5-40d2-99d0-b9a2209a4e11
+UID:ae2e2388-e584-4d17-997d-94cb5742a83d
 DESCRIPTION:Arrive by - 2024-02-24 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&
@@ -103,7 +103,7 @@ SUMMARY:(League) Tongham U12 (5th) VS Down Grange Pumas (3rd)
 DTSTART:20240302T093000
 DTEND:20240302T113000
 DTSTAMP:20240302T093000Z
-UID:d2e5ecf8-73f9-4228-95a5-ee769b7bdb87
+UID:a671f2d0-d018-4ca1-8647-7b2a77e678af
 DESCRIPTION:Arrive by - 2024-03-02 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&
@@ -116,7 +116,7 @@ SUMMARY:(League) Down Grange Pumas (3rd) VS Farnham Town Panthers (1st)
 DTSTART:20240309T093000
 DTEND:20240309T113000
 DTSTAMP:20240309T093000Z
-UID:c7fdf5dc-8674-415f-ad06-ad71464f8407
+UID:ae09571c-7a42-47b9-ba22-d6e7d2580e96
 DESCRIPTION:Arrive by - 2024-03-09 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&
@@ -130,7 +130,7 @@ SUMMARY:(League) Down Grange Pumas (3rd) VS Fernhurst Sports Terriers (4th
 DTSTART:20240316T093000
 DTEND:20240316T113000
 DTSTAMP:20240316T093000Z
-UID:645998eb-7303-4956-9e22-088c84651db4
+UID:5d6c2d8f-57a5-4240-8b2a-b1cd48c8fcf4
 DESCRIPTION:Arrive by - 2024-03-16 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&
@@ -143,7 +143,7 @@ SUMMARY:(League) Down Grange Pumas (3rd) VS Tongham U12 (5th)
 DTSTART:20240406T093000
 DTEND:20240406T113000
 DTSTAMP:20240406T093000Z
-UID:d4bb6790-c828-4447-8111-88a0c63986bb
+UID:db37b1df-e817-437b-b517-87b1ae8d3862
 DESCRIPTION:Arrive by - 2024-04-06 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&
@@ -157,7 +157,7 @@ SUMMARY:(League) Down Grange Pumas (3rd) VS Curley Park Rangers Mambas (8t
 DTSTART:20240423T093000
 DTEND:20240423T113000
 DTSTAMP:20240423T093000Z
-UID:cde4ae49-5851-4295-b3f7-11e9250a934b
+UID:eb585c7b-3203-4bb6-928f-2c06e479809e
 DESCRIPTION:Arrive by - 2024-04-23 09:00:00\nNo Match Notes\n Table - \nht
  tps://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivisi
  on=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&

+ 20 - 1
main.py

@@ -3,7 +3,9 @@ from icalendar import Calendar, Event
 from datetime import datetime, timedelta
 import uuid
 import os
+import csv
 import requests
+import lxml.html as lh
 
 telegram_bot_api_key = USER = os.getenv('TELEGRAM_BOT_API_KEY')
 telegram_bot_chat_id = USER = os.getenv('TELEGRAM_BOT_CHAT_ID')
@@ -104,7 +106,7 @@ def create_ical_file(df:pd.DataFrame, cal:Calendar, table:pd.DataFrame)->None:
         notes = row['Status / Notes']
         if pd.isna(notes):
             notes = 'No Match Notes'
-        event.add('description', "Arrive by - " + str(arrival_time) + "\n" + notes + "\n Table - \n" + "https://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivision=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&ftsTablePageContent.fixtureAnalysisForm.standingsTableMonth=0&ftsTablePageContent.fixtureAnalysisForm.standingsTableYear=2024&activeTab=1")
+        event.add('description', "Arrive by - " + str(arrival_time) + "\n" + notes + "\nTable -\n" + "https://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivision=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=14&ftsTablePageContent.fixtureAnalysisForm.standingsTableMonth=0&ftsTablePageContent.fixtureAnalysisForm.standingsTableYear=2024&activeTab=1")
         event.add('dtstart', start_date_time)
         # End 2 hours after start_date_time
         event.add('dtend', start_date_time + timedelta(hours=2))
@@ -126,6 +128,22 @@ def process_table(table_df:pd.DataFrame)->pd.DataFrame:
     store_df_as_csv(table_df, "table")
     return table_df
 
+def process_results()->None:
+    req = requests.get("https://fulltime.thefa.com/results.html?selectedSeason=19010414&selectedFixtureGroupAgeGroup=11&selectedFixtureGroupKey=1_579285719&selectedRelatedFixtureOption=1&selectedClub=&selectedTeam=466317969&selectedDateCode=all&previousSelectedFixtureGroupAgeGroup=11&previousSelectedFixtureGroupKey=1_579285719&previousSelectedClub=")
+
+    doc = lh.fromstring(req.text)
+    headers = ['Date', 'Home Team', 'Score', 'Away Team']
+
+    with open('results.csv', 'w', newline='') as fp:
+        file = csv.writer(fp)    
+        file.writerow(headers)    
+        for idx,row in enumerate(doc.xpath("//div[contains(@id,'fixture')]"), start=1):
+            date = row.xpath(f'/html[1]/body[1]/main[1]/div[2]/section[1]/div[1]/div[3]/div[1]/div[2]/div[{idx}]/div[1]/div[3]/a[1]/span[1]//text()')[0]
+            home_team = row.xpath(f'/html[1]/body[1]/main[1]/div[2]/section[1]/div[1]/div[3]/div[1]/div[2]/div[{idx}]/div[1]/div[4]/div[1]/a[1]//text()')[0].strip()
+            score = row.xpath(f'/html[1]/body[1]/main[1]/div[2]/section[1]/div[1]/div[3]/div[1]/div[2]/div[{idx}]/div[1]/div[5]//text()')[0].strip()
+            away_team = row.xpath(f'/html[1]/body[1]/main[1]/div[2]/section[1]/div[1]/div[3]/div[1]/div[2]/div[{idx}]/div[1]/div[6]/div[2]/a[1]//text()')[0].strip()
+            file.writerow([date,home_team,score,away_team])
+
 def compare_table():
     table_df = pd.read_html("https://fulltime.thefa.com/table.html?selectedSeason=19010414&selectedDivision=165601607&ftsTablePageContent.fixtureAnalysisForm.standingsTableDay=13&ftsTablePageContent.fixtureAnalysisForm.standingsTableMonth=0&ftsTablePageContent.fixtureAnalysisForm.standingsTableYear=2024&activeTab=1")[0]    
     store_df_as_csv(table_df, "base_table")
@@ -136,6 +154,7 @@ cal.add('prodid', 'Down Grange Pumas Fixtures')
 cal.add('version', '2.0')
 fixtures_df = pd.read_html("https://fulltime.thefa.com/fixtures.html?selectedSeason=19010414&selectedFixtureGroupAgeGroup=11&selectedFixtureGroupKey=1_579285719&selectedDateCode=all&selectedClub=&selectedTeam=466317969&selectedRelatedFixtureOption=3&selectedFixtureDateStatus=&selectedFixtureStatus=&previousSelectedFixtureGroupAgeGroup=11&previousSelectedFixtureGroupKey=1_579285719&previousSelectedClub=&itemsPerPage=25")[0]
 fixtures_df.head()
+process_results()
 table = compare_table()
 exists = does_csv_exist()
 if exists:

+ 4 - 0
results.csv

@@ -0,0 +1,4 @@
+Date,Home Team,Score,Away Team
+13/01/24,Farnham Town U12 Panthers,2 - 3,Down Grange U12 Pumas
+16/12/23,Mytchett Athletic U12 Hawks,2 - 4,Down Grange U12 Pumas
+25/11/23,Aldershot B&G U12 Lions,2 - 4,Down Grange U12 Pumas