Skip to content

Commit

Permalink
Merge pull request #5 from md-arif-shaikh/live_score
Browse files Browse the repository at this point in the history
Live score
  • Loading branch information
md-arif-shaikh authored Oct 14, 2021
2 parents 9f8599c + 0d9b84c commit c486cad
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
23 changes: 12 additions & 11 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#+html: <div> <img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/md-arif-shaikh/soccer"> <img alt="GitHub" src="https://img.shields.io/github/license/md-arif-shaikh/soccer"> <a href="https://melpa.org/#/soccer"><img alt="MELPA" src="https://melpa.org/packages/soccer-badge.svg"/></a> <a href="https://stable.melpa.org/#/soccer"><img alt="MELPA Stable" src="https://stable.melpa.org/packages/soccer-badge.svg"/></a></div>

* About the package
~Soccer~ is an [[https://www.gnu.org/software/emacs/][Emacs]] package for getting fixtures, results, standing table for soccer (football) matches inside emacs. Currently it works for
~Soccer~ is an [[https://www.gnu.org/software/emacs/][Emacs]] package for getting fixtures, results, standing table, scorecard etc for soccer (football) matches inside emacs. Currently it works for
- Premier League (England)
- La Liga (Spain)
- Ligue 1 (France)
Expand All @@ -23,16 +23,17 @@
* Common interactive functions
Call these using ~M-x Function~ where ~Function~ is any of the following functions

| Functions | Actions |
| ~soccer-fixtures-next~ | Fixture for the Next match |
| ~soccer-fixtures-next-5~ | Fixtures of the Next 5 matches |
| ~soccer-fixtures-full-in-org~ | Full fixtures saved in org file |
| ~soccer-results-last~ | Result of the last match |
| ~soccer-results-last-5~ | Results of the last 5 matches |
| ~soccer-results-full-in-org~ | Full list of results in org file |
| ~soccer-table~ | Full Ranking table |
| ~soccer-table-top-4~ | Rank table with top 4 teams |
| ~soccer-table-bottom-4~ | Rank table with bottom 4 teams |
| Functions | Actions |
| ~soccer-fixtures-next~ | Fixture for the Next match |
| ~soccer-fixtures-next-5~ | Fixtures of the Next 5 matches |
| ~soccer-fixtures-full-in-org~ | Full fixtures saved in org file |
| ~soccer-results-last~ | Result of the last match |
| ~soccer-results-last-5~ | Results of the last 5 matches |
| ~soccer-results-full-in-org~ | Full list of results in org file |
| ~soccer-table~ | Full Ranking table |
| ~soccer-table-top-4~ | Rank table with top 4 teams |
| ~soccer-table-bottom-4~ | Rank table with bottom 4 teams |
| ~soccer-scorecard~ | Scorecard |
* Screenshots
- ~soccer-fixtures-next-5~
#+html: <div> <img src="./screenshots/soccer-fixtures-next-5.png"> </div>
Expand Down
58 changes: 53 additions & 5 deletions soccer.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Md Arif Shaikh <arifshaikh.astro@gmail.com>
;; Homepage: https://github.com/md-arif-shaikh/soccer
;; Package-Requires: ((emacs "26.1") (dash "2.19.1"))
;; Version: 1.0.0
;; Version: 1.1.0
;; Keywords: games, soccer, football

;; This program is free software; you can redistribute it and/or modify
Expand All @@ -28,7 +28,7 @@
;;
;; 1. Premier League (England)
;; 2. La Liga (Spain)
;; 3. League 1 (France)
;; 3. Ligue 1 (France)
;;
;; Other leagues could be easily included and would be in future.
;;
Expand All @@ -49,9 +49,10 @@
;; soccer-results-last Result of the last match
;; soccer-results-last-5 Results of the last 5 matches
;; soccer-results-full-in-org Full list of results in org file
;; soccer-table Full Ranking table
;; soccer-table-top-4 Ranking table with top 4 teams
;; soccer-table-bottom-4 Ranking table with bottom 4 teams
;; soccer-table Full Ranking table
;; soccer-table-top-4 Ranking table with top 4 teams
;; soccer-table-bottom-4 Ranking table with bottom 4 teams
;; soccer-scorecard Scorecard of a match

;;; Code:

Expand Down Expand Up @@ -405,5 +406,52 @@
(list league-name club-name)))
(soccer--get-league-data league club "results" 5))

;; score card
(defun soccer--get-scorecard-alist (date home away)
"Get the live scorecard for a match between HOME and AWAY on DATE. DATE should in the format DD-MM-YYYY."
(let* ((live-match-url (downcase (string-replace " " "-" (concat "https://www.scorespro.com/soccer/livescore/" home "-vs-" away "/" date "/")))))
(with-current-buffer (url-retrieve-synchronously live-match-url)
(let* ((dom (libxml-parse-html-region (point-min) (point-max)))
(title (dom-strings (dom-by-tag dom 'title)))
(home-goal-scorers (dom-strings (dom-by-class dom "sp-goalscorers__home-team")))
(away-goal-scorers (dom-strings (dom-by-class dom "sp-goalscorers__away-team")))
(home-goals (/ (length home-goal-scorers) 2))
(away-goals (/ (length away-goal-scorers) 2))
(home-scorecard-strings-list (-partition 2 home-goal-scorers))
(away-scorecard-strings-list (-partition 2 away-goal-scorers)))
`(("title" . ,title)
("home-goals" . ,home-goals)
("away-goals" . ,away-goals)
("home-scorecard-list" . ,home-scorecard-strings-list)
("away-scorecard-list" . ,away-scorecard-strings-list))))))

(defun soccer--all-clubs ()
"Get all club names."
(-flatten (cl-loop for leagues in (soccer--league-names)
collect (mapcar 'car (cdr (assoc leagues soccer-leagues--leagues-alist))))))

(defun soccer-scorecard (date home away)
"Get the socrecard for a match between HOME and AWAY on a DATE. Enter DATE in YYYY-MM-DD format if entering it manually. If the input is from `org-read-date' calendar popup then it is in YYYY-MM-DD format by default."
(interactive
(list (org-read-date nil nil nil "Date of the match: ") (completing-read "home club/nation: " (soccer--all-clubs)) (completing-read "away club/nation: " (soccer--all-clubs))))
(let* ((day-moth-year (soccer-time--get-day-month-year-number-from-date date "-" 2 1 0))
(dd (-first-item day-moth-year))
(mm (-second-item day-moth-year))
(yyyy (-third-item day-moth-year))
(new-date (format "%02d-%02d-%04d" dd mm yyyy))
(scorecard-alist (soccer--get-scorecard-alist new-date home away))
(title (cdr (assoc "title" scorecard-alist))))
(if title
(let* ((home-goals (cdr (assoc "home-goals" scorecard-alist)))
(away-goals (cdr (assoc "away-goals" scorecard-alist)))
(home-scorecard-list (cdr (assoc "home-scorecard-list" scorecard-alist)))
(away-scorecard-list (cdr (assoc "away-scorecard-list" scorecard-alist)))
(home-scorecard (format "%s %s: %s" home home-goals (string-join (cl-loop for g in home-scorecard-list
collect (format "%s(%s)" (-second-item g) (-first-item g))) " ")))
(away-scorecard (format "%s %s: %s" away away-goals (string-join (cl-loop for g in away-scorecard-list
collect (format "%s(%s)" (-second-item g) (-first-item g))) " "))))
(message (format "%s\n%s" home-scorecard away-scorecard)))
(message "Result not found. Probably entered wrong date/name?"))))

(provide 'soccer)
;;; soccer.el ends here

0 comments on commit c486cad

Please sign in to comment.