Coder Social home page Coder Social logo

fotmob's Introduction

fotmob

license standard-readme compliant npm npm download month Node.js CI

A JavaScript wrapper around the unofficial FotMob API

Table of Contents

Install

npm install fotmob

Usage

This package is meant to be used in the backend (Node.js) due to CORS limitations. All methods return a promise that resolves to the JSON response from FotMob, with type definitions for the response included.

import Fotmob from "fotmob";
const fotmob = new Fotmob();

let matches = await fotmob.getMatchesByDate("20201020");
let league = await fotmob.getLeague("42", "overview", "league", "America/New_York")
let team = await fotmob.getTeam("6017", "overview", "team", "America/New_York")
let player = await fotmob.getPlayer("1071179")
let details = await fotmob.getMatchDetails("3399269")
let worldNews = await fotmob.getWorldNews()
let transfers = await fotmob.getTransfers();
let AllLeagues = await fotmob.getAllLeagues();
let teamSeasonStats = await fotmob.getTeamSeasonStats()
let myCustomRequest = await fotmob.request("matches", { date: "20201020" })

Contributing

Feel free to open an issue or submit a pull request.

License

MIT © Brian Greenwood

fotmob's People

Contributors

bgrnwd avatar dependabot[bot] avatar itamarshdev avatar jamtur01 avatar markosullivan94 avatar mtslzr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fotmob's Issues

[BUG] Fotmob is not a constructor

Environment

  • Windows 11 x64
  • NodeJS 21.6.0
  • NPM 10.2.4

Problem

I'm trying to import into a nodejs server a fotmob-api.mjs file containg the code example from the README.md
These are my files:

app.js

const express = require('express');
const { createServer } = require('node:http');
const { join } = require('node:path');
const { Server } = require('socket.io');

const app = express();
const server = createServer(app);
const io = new Server(server);

var fotmob = null
import("./libs/fotmob_api.mjs").then(mod => fotmob = mod)

app.use(express.static('public'))

app.get('/', (req, res) => {
  res.sendFile(join(__dirname + "/views/", 'index.html'));
});

io.on('connection', (socket) => {
  console.log('a user connected');

  //Handle Disconnection
  socket.on('disconnect', () => {
    console.log('user disconnected');
  });

  socket.on('to_server', (msg) => {
    console.log('I\'m the server, I received %s from %s', msg, socket.id);
    socket.emit("from_server", "Hello from the server!")
  })
});

server.listen(3000, () => {
  console.log('server running at http://localhost:3000');
});

and the library I'm trying to import

libs/fotmob_api.mjs

//ECMA

import Fotmob from 'fotmob';
const fotmob = new Fotmob();

let matches = await fotmob.getMatchesByDate("20201020");
let league = await fotmob.getLeague("42", "overview", "league", "America/New_York")
let team = await fotmob.getTeam("6017", "overview", "team", "America/New_York")
let player = await fotmob.getPlayer("1071179")
let details = await fotmob.getMatchDetails("3399269")
let worldNews = await fotmob.getWorldNews()
let myCustomRequest = await fotmob.request("matches", { date: "20201020" })

I'm probably importing it in the wrong way, an ES module inside a CommonJS one. But still, any idea on why it says that Fotmob is not a constructor? Or any idea on how to import it correctly as a separated file into my nodejs main? Here's the error I'm getting:

const fotmob = new Fotmob();
               ^

TypeError: Fotmob is not a constructor
    at file:///C:/Users/Francesco/Downloads/milan-voter/libs/fotmob_api.mjs:4:16
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:430:15)

Node.js v21.6.0

[BUG] Invalid value for key Header

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\types\match-details.js:807 throw Error('Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}');

Error: Invalid value for key "header" on MatchDetails. Expected an optional object but got {"teams":[{"name":"Barcelona","id":8634,"score":2,"imageUrl":"https://images.fotmob.com/image_resources/logo/teamlogo/8634_small.png","pageUrl":"/teams/8634/overview/barcelona","fifaRank":null},{"name":"Bayern München","id":9823,"score":8,"imageUrl":"https://images.fotmob.com/image_resources/logo/teamlogo/9823_small.png","pageUrl":"/teams/9823/overview/bayern-munchen","fifaRank":null}],"status":{"utcTime":"2020-08-14T19:00:00.000Z","homeRedCards":[],"awayRedCards":[],"finished":true,"started":true,"cancelled":false,"scoreStr":"2 - 8","reason":{"short":"FT","shortKey":"fulltime_short","long":"Full-Time","longKey":"finished"},"whoLostOnPenalties":null,"whoLostOnAggregated":""},"events":{"homeTeamGoals":{"Alaba":[{"reactKey":"7Goal121633undefinedtrue","timeStr":7,"type":"Goal","time":7,"overloadTime":null,"eventId":7219005,"player":{"id":121633,"name":"David Alaba","profileUrl":"/players/121633/david-alaba"},"profileUrl":"/players/121633/david-alaba","overloadTimeStr":false,"isHome":true,"ownGoal":true,"goalDescription":"Own goal","goalDescriptionKey":"owngoal","suffix":"OG","suffixKey":"own_goal_short","isPenaltyShootoutEvent":false,"nameStr":"David Alaba","firstName":"David","lastName":"Alaba","fullName":"David Alaba","playerId":121633,"newScore":[1,1],"penShootoutScore":null,"shotmapEvent":null,"assistStr":null,"assistProfileUrl":null}],"Suárez":[{"reactKey":"57Goal40636undefinedtrue","timeStr":57,"type":"Goal","time":57,"overloadTime":null,"eventId":7219141,"player":{"id":40636,"name":"Luis Suárez","profileUrl":"/players/40636/luis-suarez"},"profileUrl":"/players/40636/luis-suarez","overloadTimeStr":false,"isHome":true,"ownGoal":null,"goalDescription":null,"goalDescriptionKey":null,"suffix":null,"suffixKey":null,"isPenaltyShootoutEvent":false,"nameStr":"Luis Suárez","firstName":"Luis","lastName":"Suárez","fullName":"Luis Suárez","playerId":40636,"newScore":[2,4],"penShootoutScore":null,"shotmapEvent":null,"assistStr":"assist by Jordi Alba","assistProfileUrl":"/players/150739/jordi-alba","assistPlayerId":150739,"assistKey":"assist_by","assistInput":"Jordi Alba"}]},"awayTeamGoals":{"Müller":[{"reactKey":"4Goal116772undefinedfalse","timeStr":4,"type":"Goal","time":4,"overloadTime":null,"eventId":7218999,"player":{"id":116772,"name":"Thomas Müller","profileUrl":"/players/116772/thomas-muller"},"profileUrl":"/players/116772/thomas-muller","overloadTimeStr":false,"isHome":false,"ownGoal":null,"goalDescription":null,"goalDescriptionKey":null,"suffix":null,"suffixKey":null,"isPenaltyShootoutEvent":false,"nameStr":"Thomas Müller","firstName":"Thomas","lastName":"Müller","fullName":"Thomas Müller","playerId":116772,"newScore":[0,1],"penShootoutScore":null,"shotmapEvent":null,"assistStr":"assist by Robert Lewandowski","assistProfileUrl":"/players/93447/robert-lewandowski","assistPlayerId":93447,"assistKey":"assist_by","assistInput":"Robert Lewandowski"},{"reactKey":"31Goal116772undefinedfalse","timeStr":31,"type":"Goal","time":31,"overloadTime":null,"eventId":7219040,"player":{"id":116772,"name":"Thomas Müller","profileUrl":"/players/116772/thomas-muller"},"profileUrl":"/players/116772/thomas-muller","overloadTimeStr":false,"isHome":false,"ownGoal":null,"goalDescription":null,"goalDescriptionKey":null,"suffix":null,"suffixKey":null,"isPenaltyShootoutEvent":false,"nameStr":"Thomas Müller","firstName":"Thomas","lastName":"Müller","fullName":"Thomas Müller","playerId":116772,"newScore":[1,4],"penShootoutScore":null,"shotmapEvent":null,"assistStr":"assist by Joshua Kimmich","assistProfileUrl":"/players/460632/joshua-kimmich","assistPlayerId":460632,"assistKey":"assist_by","assistInput":"Joshua Kimmich"}],"Perisic":[{"reactKey":"22Goal163670undefinedfalse","timeStr":22,"type":"Goal","time":22,"overloadTime":null,"eventId":7219022,"player":{"id":163670,"name":"Ivan Perisic","profileUrl":"/players/163670/ivan-perisic"},"profileUrl":"/players/163670/ivan-perisic","overloadTimeStr":false,"isHome":false,"ownGoal":null,"goalDescription":null,"goalDescriptionKey":null,"suffix":null,"suffixKey":null,"isPenaltyShootoutEvent":false,"nameStr":"Ivan Perisic","firstName":"Ivan","lastName":"Perisic","fullName":"Ivan Perisic","playerId":163670,"newScore":[1,2],"penShootoutScore":null,"shotmapEvent":null,"assistStr":"assist by Serge Gnabry","assistProfileUrl":"/players/385437/serge-gnabry","assistPlayerId":385437,"assistKey":"assist_by","assistInput":"Serge Gnabry"}],"Gnabry":[{"reactKey":"27Goal385437undefinedfalse","timeStr":27,"type":"Goal","time":27,"overloadTime":null,"eventId":7219033,"player":{"id":385437,"name":"Serge Gnabry","profileUrl":"/players/385437/serge-gnabry"},"profileUrl":"/players/385437/serge-gnabry","overloadTimeStr":false,"isHome":false,"ownGoal":null,"goalDescription":null,"goalDescriptionKey":null,"suffix":null,"suffixKey":null,"isPenaltyShootoutEvent":false,"nameStr":"Serge Gnabry","firstName":"Serge","lastName":"Gnabry","fullName":"Serge Gnabry","playerId":385437,"newScore":[1,3],"penShootoutScore":null,"shotmapEvent":null,"assistStr":"assist by Leon Goretzka","assistProfileUrl":"/players/343748/leon-goretzka","assistPlayerId":343748,"assistKey":"assist_by","assistInput":"Leon Goretzka"}],"Kimmich":[{"reactKey":"63Goal460632undefinedfalse","timeStr":63,"type":"Goal","time":63,"overloadTime":null,"eventId":7219157,"player":{"id":460632,"name":"Joshua Kimmich","profileUrl":"/players/460632/joshua-kimmich"},"profileUrl":"/players/460632/joshua-kimmich","overloadTimeStr":false,"isHome":false,"ownGoal":null,"goalDescription":null,"goalDescriptionKey":null,"suffix":null,"suffixKey":null,"isPenaltyShootoutEvent":false,"nameStr":"Joshua Kimmich","firstName":"Joshua","lastName":"Kimmich","fullName":"Joshua Kimmich","playerId":460632,"newScore":[2,5],"penShootoutScore":null,"shotmapEvent":null,"assistStr":"assist by Alphonso Davies","assistProfileUrl":"/players/751202/alphonso-davies","assistPlayerId":751202,"assistKey":"assist_by","assistInput":"Alphonso Davies"}],"Lewandowski":[{"reactKey":"82Goal93447undefinedfalse","timeStr":82,"type":"Goal","time":82,"overloadTime":null,"eventId":7219213,"player":{"id":93447,"name":"Robert Lewandowski","profileUrl":"/players/93447/robert-lewandowski"},"profileUrl":"/players/93447/robert-lewandowski","overloadTimeStr":false,"isHome":false,"ownGoal":null,"goalDescription":null,"goalDescriptionKey":null,"suffix":null,"suffixKey":null,"isPenaltyShootoutEvent":false,"nameStr":"Robert Lewandowski","firstName":"Robert","lastName":"Lewandowski","fullName":"Robert Lewandowski","playerId":93447,"newScore":[2,6],"penShootoutScore":null,"shotmapEvent":null,"assistStr":"assist by Philippe Coutinho","assistProfileUrl":"/players/184536/philippe-coutinho","assistPlayerId":184536,"assistKey":"assist_by","assistInput":"Philippe Coutinho"}],"Coutinho":[{"reactKey":"85Goal184536undefinedfalse","timeStr":85,"type":"Goal","time":85,"overloadTime":null,"eventId":7219242,"player":{"id":184536,"name":"Philippe Coutinho","profileUrl":"/players/184536/philippe-coutinho"},"profileUrl":"/players/184536/philippe-coutinho","overloadTimeStr":false,"isHome":false,"ownGoal":null,"goalDescription":null,"goalDescriptionKey":null,"suffix":null,"suffixKey":null,"isPenaltyShootoutEvent":false,"nameStr":"Philippe Coutinho","firstName":"Philippe","lastName":"Coutinho","fullName":"Philippe Coutinho","playerId":184536,"newScore":[2,7],"penShootoutScore":null,"shotmapEvent":null,"assistStr":"assist by Thomas Müller","assistProfileUrl":"/players/116772/thomas-muller","assistPlayerId":116772,"assistKey":"assist_by","assistInput":"Thomas Müller"},{"reactKey":"89Goal184536undefinedfalse","timeStr":89,"type":"Goal","time":89,"overloadTime":null,"eventId":7219246,"player":{"id":184536,"name":"Philippe Coutinho","profileUrl":"/players/184536/philippe-coutinho"},"profileUrl":"/players/184536/philippe-coutinho","overloadTimeStr":false,"isHome":false,"ownGoal":null,"goalDescription":null,"goalDescriptionKey":null,"suffix":null,"suffixKey":null,"isPenaltyShootoutEvent":false,"nameStr":"Philippe Coutinho","firstName":"Philippe","lastName":"Coutinho","fullName":"Philippe Coutinho","playerId":184536,"newScore":[2,8],"penShootoutScore":null,"shotmapEvent":null,"assistStr":"assist by Lucas Hernández","assistProfileUrl":"/players/504606/lucas-hernandez","assistPlayerId":504606,"assistKey":"assist_by","assistInput":"Lucas Hernández"}]}}} at invalidValue (E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\types\match-details.js:807:11) at transformUnion (E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\types\match-details.js:860:16) at transform (E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\types\match-details.js:921:15) at E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\types\match-details.js:894:32 at Array.forEach (<anonymous>) at transformObject (E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\types\match-details.js:889:43) at transform (E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\types\match-details.js:925:23) at cast (E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\types\match-details.js:933:12) at toMatchDetails (E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\types\match-details.js:160:16) at Fotmob.<anonymous> (E:\Proyectos\scrap-fotmob\node_modules\fotmob\dist\cjs\fotmob.js:56:24)

Expected Behavior

For Fotmob v2.4.0, The await fotmob.getMatchDetails(3363666); should return an object with the match details

Steps To Reproduce

  1. Create a new project for TS/JS
  2. Install the Fotmob Library
  3. Call the getMatchDetails method with some matchId
  4. Get the error

Environment

- OS: Windows 11
- Node: v18.18.0
- npm: 9.8.1

Version

1.0.0

Anything else?

No response

Example usage is not working correctly

Describe the bug
Using the example provided in the README.md returns a large HTML response (presumably from the error page of the FotMob website)

To Reproduce
Steps to reproduce the behavior:

import Fotmob from 'fotmob';
const fotmob = new Fotmob();

fotmob.getMatchesByDate("20201020");
fotmob.getLeague("42", "overview", "league", "America/New_York");
fotmob.getTeam("6017", "overview", "team", "America/New_York");
fotmob.getPlayer("1071179");
fotmob.getMatchDetails("3399269");

Expected behavior
Expected getPlayer for example to return me a JSON payload.

Screenshots
Screenshot 2022-08-31 at 16 00 23

Desktop (please complete the following information):

  • OS: MacOS 12.5.1
  • Browser: Brave (Version 1.42.97 Chromium: 104.0.5112.102 (Official Build) (x86_64))

CORS Issues

Describe the bug
Every API call is blocked by CORS policy

To Reproduce
Steps to reproduce the behavior:

  1. Create a new Angular Project
  2. Install package
  3. Do any http call
  4. Error Access to XMLHttpRequest at 'https://www.fotmob.com/api/matchDetails?matchId=3917969' from origin 'https://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Expected behavior
JSON result to be printed

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • Version Last stable

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.