mvan231

LS widget

Apr 5th, 2023
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. // Variables used by Scriptable.
  2. // These must be at the very top of the file. Do not edit.
  3.  
  4. const w = new ListWidget()
  5.  
  6. // Main
  7. const url = 'https://v3.football.api-sports.io/fixtures?season=2022&team=541&next=1'
  8. const request = new Request(url)
  9. request.headers = { 'X-RapidAPI-Key': 'c01ea45df19fa5fa1b45aa8d9bcd1a36' }
  10. const response = await request.loadJSON()
  11. const matchday = response.response[0].fixture.date
  12. var date = new Date(matchday);
  13. var max = date.toString()
  14. mydate = new Date(max);
  15.  
  16. w.setPadding(5, 5, 20, 5)
  17. w.spacing = 0
  18.  
  19. // Home Team
  20. w.addSpacer()
  21.  
  22. let main = w.addStack()
  23.  
  24. let left = main.addStack()
  25. let right = main.addStack()
  26.  
  27. let leftContent = left.addStack()
  28. leftContent.size = new Size(75, 20)
  29. leftContent.borderColor = Color.red()
  30. leftContent.borderWidth = 0
  31. leftContent.addSpacer()
  32. const imgURL = response.response[0].teams.home.logo
  33. let imgRequest = new Request(imgURL);
  34. let img = await imgRequest.loadImage();
  35. let HomeTeamlogo = new ListWidget()
  36. let homeImage = leftContent.addImage(img);
  37. homeImage.imageSize = new Size(20, 20);
  38.  
  39.  
  40. // Away Team
  41. let rightContent = right.addStack()
  42. rightContent.size = new Size(75, 20)
  43. rightContent.borderColor = Color.red()
  44. rightContent.borderWidth = 0
  45. const URL = response.response[0].teams.away.logo
  46. let imageRequest = new Request(URL);
  47. let image = await imageRequest.loadImage();
  48. let awayImage = rightContent.addImage(image);
  49. awayImage.imageSize = new Size(20, 20);
  50. rightContent.addSpacer()
  51.  
  52. // Time
  53. fax = mydate.toLocaleDateString("es-PA");
  54. const months = ["Jan", "Feb", "Mar","Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
  55. let current_datetime = new Date(mydate)
  56. let formatted_date = current_datetime.getDate() + " " + months[current_datetime.getMonth()]
  57. time = mydate.toLocaleString([], {hour: 'numeric',minute:'numeric'});
  58. time = ". " + time
  59. Match = new Date(date).toLocaleDateString('af-ZA');
  60.  
  61. // Current Date
  62. now = new Date();
  63. now = now.setDate(now.getDate());
  64. CurrentDate = new Date(now).toLocaleDateString('af-ZA');
  65.  
  66. // Difference of Match dates
  67. const diffTime = Math.max(new Date(Match) - new Date(CurrentDate));
  68. const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
  69.  
  70. test3 = diffDays;
  71.  
  72. let hello3 = "";
  73.  
  74. if (test3 == 0) {
  75. hello3 = "Today";
  76. Matchdate = w.addText(hello3)
  77. Matchdate.font = Font.boldSystemFont(5)
  78. }
  79. else if (test3 == 1) {
  80. hello3 = "Tomorrow";
  81. Matchdate = w.addText(hello3)
  82. Matchdate.font = Font.boldSystemFont(5)
  83. }
  84. else {
  85. hello3 = formatted_date;
  86. Matchdate = w.addText(hello3)
  87. Matchdate.font = Font.boldSystemFont(5)
  88. }
  89. Matchdate.centerAlignText()
  90.  
  91. Time = w.addText(time)
  92. Time.centerAlignText()
  93. Time.font = Font.boldSystemFont(5)
  94.  
  95. w.addSpacer()
  96. w.minimumScaleFactor = 0.4
  97.  
  98. const titlew = hello3;
  99. w.addAccessoryWidgetBackground = true
  100.  
  101. Script.setWidget(w)
  102. Script.complete()
  103. w.presentAccessoryRectangular()
Advertisement
Add Comment
Please, Sign In to add comment