Browse Source

refactor(icons) clean up icon function

Joe Richardson 1 year ago
parent
commit
43f71845a8
1 changed files with 14 additions and 31 deletions
  1. 14
    31
      index.js

+ 14
- 31
index.js View File

@@ -1,8 +1,7 @@
1
-require("dotenv").config();
1
+require(`dotenv`).config();
2 2
 
3
-// Imports
4
-const fetch = require("node-fetch");
5
-const twitter = require("twitter");
3
+const fetch = require(`node-fetch`);
4
+const twitter = require(`twitter`);
6 5
 
7 6
 // Twitter
8 7
 const client = new twitter({
@@ -24,50 +23,34 @@ fetch(url)
24 23
   .then(function(weather) {
25 24
     const label = weather.weather[0].description;
26 25
 
27
-    // TODO: clean this up
28 26
     function icon() {
29
-      if (label.includes("clouds")) {
30
-        return `☁ `;
31
-      }
32
-
33
-      if (label.includes("clear")) {
34
-        return `☀️ `;
35
-      }
36
-
37
-      if (label.includes("rain")) {
38
-        return `🌧 `;
39
-      }
40
-
41
-      if (label.includes("thunderstorm")) {
42
-        return `⛈ `;
43
-      }
44
-
45
-      if (label.includes("snow")) {
46
-        return `❄️ `;
47
-      }
48
-
49
-      return `⭐️ `;
27
+      if (label.includes(`clouds`)) return `☁`;
28
+      if (label.includes(`clear`)) return `☀️`;
29
+      if (label.includes(`rain`)) return `🌧`;
30
+      if (label.includes(`thunderstorm`)) return `⛈`;
31
+      if (label.includes(`snow`)) return `❄️`;
32
+      return `Update:`;
50 33
     }
51 34
 
52 35
     function time() {
53 36
       const time = new Date();
54 37
       if (time.getHours() === 7) {
55
-        return `7am`
38
+        return `7am`;
56 39
       } else {
57
-        return `6pm`
40
+        return `6pm`;
58 41
       }
59 42
     }
60 43
 
61
-    const output = `${icon()} It's ${time()} in ${LOCATION} the temperature is ${Math.round(
44
+    const output = `${icon()}  It's ${time()} in ${LOCATION} the temperature is ${Math.round(
62 45
       weather.main.temp
63 46
     )}°C with a high of ${Math.round(weather.main.temp_max)}°C and a low of ${Math.round(
64 47
       weather.main.temp_min
65 48
     )}°C.`;
66 49
 
67
-    console.log(output)
50
+    console.log(output);
68 51
 
69 52
     const params = { screen_name: "nodejs" };
70
-    client.post("statuses/update", { status: output }, function(error, tweet, response) {
53
+    client.post("statuses/update", { status: output }, function (error, tweet, response) {
71 54
       if (!error) {
72 55
         console.log(tweet);
73 56
       }