Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Variables used by Scriptable.
- // These must be at the very top of the file. Do not edit.
- const w = new ListWidget()
- // Main
- const url = 'https://v3.football.api-sports.io/fixtures?season=2022&team=541&next=1'
- const request = new Request(url)
- request.headers = { 'X-RapidAPI-Key': 'c01ea45df19fa5fa1b45aa8d9bcd1a36' }
- const response = await request.loadJSON()
- const matchday = response.response[0].fixture.date
- var date = new Date(matchday);
- var max = date.toString()
- mydate = new Date(max);
- w.setPadding(5, 5, 20, 5)
- w.spacing = 0
- // Home Team
- w.addSpacer()
- let main = w.addStack()
- let left = main.addStack()
- let right = main.addStack()
- let leftContent = left.addStack()
- leftContent.size = new Size(75, 20)
- leftContent.borderColor = Color.red()
- leftContent.borderWidth = 0
- leftContent.addSpacer()
- const imgURL = response.response[0].teams.home.logo
- let imgRequest = new Request(imgURL);
- let img = await imgRequest.loadImage();
- let HomeTeamlogo = new ListWidget()
- let homeImage = leftContent.addImage(img);
- homeImage.imageSize = new Size(20, 20);
- // Away Team
- let rightContent = right.addStack()
- rightContent.size = new Size(75, 20)
- rightContent.borderColor = Color.red()
- rightContent.borderWidth = 0
- const URL = response.response[0].teams.away.logo
- let imageRequest = new Request(URL);
- let image = await imageRequest.loadImage();
- let awayImage = rightContent.addImage(image);
- awayImage.imageSize = new Size(20, 20);
- rightContent.addSpacer()
- // Time
- fax = mydate.toLocaleDateString("es-PA");
- const months = ["Jan", "Feb", "Mar","Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
- let current_datetime = new Date(mydate)
- let formatted_date = current_datetime.getDate() + " " + months[current_datetime.getMonth()]
- time = mydate.toLocaleString([], {hour: 'numeric',minute:'numeric'});
- time = ". " + time
- Match = new Date(date).toLocaleDateString('af-ZA');
- // Current Date
- now = new Date();
- now = now.setDate(now.getDate());
- CurrentDate = new Date(now).toLocaleDateString('af-ZA');
- // Difference of Match dates
- const diffTime = Math.max(new Date(Match) - new Date(CurrentDate));
- const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
- test3 = diffDays;
- let hello3 = "";
- if (test3 == 0) {
- hello3 = "Today";
- Matchdate = w.addText(hello3)
- Matchdate.font = Font.boldSystemFont(5)
- }
- else if (test3 == 1) {
- hello3 = "Tomorrow";
- Matchdate = w.addText(hello3)
- Matchdate.font = Font.boldSystemFont(5)
- }
- else {
- hello3 = formatted_date;
- Matchdate = w.addText(hello3)
- Matchdate.font = Font.boldSystemFont(5)
- }
- Matchdate.centerAlignText()
- Time = w.addText(time)
- Time.centerAlignText()
- Time.font = Font.boldSystemFont(5)
- w.addSpacer()
- w.minimumScaleFactor = 0.4
- const titlew = hello3;
- w.addAccessoryWidgetBackground = true
- Script.setWidget(w)
- Script.complete()
- w.presentAccessoryRectangular()
Advertisement
Add Comment
Please, Sign In to add comment