Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function createWidget() {
- let listwidget = new ListWidget();
- let weatherData;
- const apiKey = "82c29fdbgd6aebbb595d402f8a65fabf";
- var cityID = "4998830";
- let fileManager = FileManager.iCloud();
- let bgPath = fileManager.documentsDirectory() + "/Widgetbg.PNG"; //Replace with your background crop
- } if (background.type == "image") {
- const extension = (this.darkMode && background.dark && !this.settings.widget.instantDark ? " (Dark)" : "") + ".jpg"
- const imagePath = this.fm.joinPath(this.fm.joinPath(this.fm.documentsDirectory(), "Weather Cal"), name + extension)
- if (this.fm.fileExists(imagePath)) {
- if (this.fm.isFileStoredIniCloud(imagePath)) { await this.fm.downloadFileFromiCloud(imagePath) }
- this.widget.backgroundImage = this.fm.readImage(imagePath)
- } else if (config.runsInWidget) {
- this.widget.backgroundColor = Color.gray()
- const months = ["Jan", "Feb", "Mar", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
- const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
- const d = new Date();
- let month = months[d.getMonth()];
- let day = days[d.getDay()];
- let numDay = d.getDate();
- let hour = d.getHours();
- try {
- weatherData = await new Request("https://api.openweathermap.org/data/2.5/weather?id="+ cityID +"&appid=" + apiKey).loadJSON();
- console.log(weatherData);
- }catch(e){
- console.log("nothing");
- }
- var farenheit = Math.round(((parseFloat(weatherData.main.temp)-273.15)*1.8)+32);;
- function dateOrdinal(int) {
- if (int == 31 || int == 21 || int == 1) return int + "st";
- else if (int == 22 || int == 2) return int + "nd";
- else if (int == 23 || int == 3) return int + "rd";
- else return int + "th";
- };
- function getTime() {
- if (hour < 12) return "Morning Blake";
- else if (hour < 18) return "Afternoon Blake";
- else return "Evening Blake";
- };
- //
- // console.log(getTime());
- function weatherMessage() {
- if (farenheit <= 40) return "Grab a scarf, Its freezing";
- else if (farenheit <= 50) return "Might want a coat";
- else if (farenheit <= 60) return "Not too bad outside";
- else if (celcius <= 68) return "Getting a bit warm outside";
- else if (celcius <= 75) return "Summertime sucks, drink water";
- else return "Nope, way too hot out there";
- }
- await fileManager.downloadFileFromiCloud(bgPath);
- listwidget.backgroundImage = Image.fromFile(bgPath);
- let heading = listwidget.addText("Good " + getTime());
- heading.leftAlignText();
- heading.font = Font.lightSystemFont(18);
- heading.textColor = new Color("#000");
- listwidget.addSpacer(5);
- let dateText = listwidget.addText("It's " + day);
- dateText.leftAlignText();
- dateText.font = Font.regularRoundedSystemFont(30);
- dateText.textColor = new Color("#000");
- let dateMonth = listwidget.addText(month + " the " + dateOrdinal(numDay));
- dateMonth.leftAlignText();
- dateMonth.font = Font.regularRoundedSystemFont(30);
- dateMonth.textColor = new Color("#000");
- listwidget.addSpacer(5);
- let weatherText = listwidget.addText("It's " + farenheit + "°F with "+ weatherData.weather[0].description + ".");
- weatherText.leftAlignText();
- weatherText.font = Font.lightSystemFont(12)
- weatherText.textColor = new Color("#000");
- let weatherTexttwo = listwidget.addText(weatherMessage());
- weatherTexttwo.leftAlignText();
- weatherTexttwo.font = Font.lightSystemFont(12)
- weatherTexttwo.textColor = new Color("#000");
- listwidget.addSpacer(80);
- return listwidget;
- }
- let widget = await createWidget();
- if (config.runsInWidget) {
- Script.setWidget(widget);
- } else {(str)
- widget.presentLarge();
- }
- Script.complete();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement