radames commited on
Commit
580d4d4
·
1 Parent(s): 8f3df85

avoid layout shifs, update text

Browse files
app.py CHANGED
@@ -35,7 +35,7 @@ def get_news():
35
 
36
  # if new homepage is newer than cache, update cache and return
37
  print("new date",nyt_homepage['last_update'])
38
- print("old date",cache['last_update'])
39
  if not cache or parser.parse(nyt_homepage['last_update']) > parser.parse(cache['last_update']):
40
  print("Updating cache with new preditions")
41
  titles = [entry['title'] for entry in nyt_homepage['entries']]
 
35
 
36
  # if new homepage is newer than cache, update cache and return
37
  print("new date",nyt_homepage['last_update'])
38
+ print("old date",cache['last_update'] if 'last_update' in cache else "None")
39
  if not cache or parser.parse(nyt_homepage['last_update']) > parser.parse(cache['last_update']):
40
  print("Updating cache with new preditions")
41
  titles = [entry['title'] for entry in nyt_homepage['entries']]
client/src/components/NewsBlock.svelte CHANGED
@@ -18,7 +18,7 @@
18
  <div class="text-sm">
19
  Score:
20
  <span class="font-bold {feedEntry.sentiment > 0 ? 'text-emerald-600' : 'text-red-600'}">
21
- {feedEntry.sentiment.toFixed(3)}
22
  </span>
23
  </div>
24
 
 
18
  <div class="text-sm">
19
  Score:
20
  <span class="font-bold {feedEntry.sentiment > 0 ? 'text-emerald-600' : 'text-red-600'}">
21
+ {feedEntry.sentiment.toFixed(4)}
22
  </span>
23
  </div>
24
 
client/src/routes/index.svelte CHANGED
@@ -11,9 +11,9 @@
11
  // hack to develop locally without having to run the server
12
  predictions = await fetch('static/test.json').then((d) => d.json());
13
  }
14
- lastUpdate = predictions.last_update;
15
  predictions = predictions.entries.sort((a, b) => b.sentiment - a.sentiment);
16
- console.log(predictions);
17
  }
18
 
19
  function toggleOrder() {
@@ -25,23 +25,33 @@
25
  </script>
26
 
27
  <div class="px-6 py-3 max-w-4xl mx-auto">
28
- <h1 class="text-4xl font-bold font-serif py-5 leading-tight">The New York Times Homepage</h1>
 
 
 
 
29
 
30
  <button
31
- class="{positiveOrder ? 'bg-emerald-600' :'bg-red-600'} bg-blue-500 hover:bg-zinc-300 text-white font-bold py-2 px-4 rounded"
 
 
32
  on:click={toggleOrder}
33
  >
34
  {!positiveOrder ? 'Sorted by negative' : 'Sorted by positive'}
35
  </button>
36
-
37
  {#await fecthPredictions()}
38
- <p>Loading and running sentiment analysis on the latest news...</p>
 
 
 
 
 
39
  {:then data}
40
  <ul>
41
  {#each predictions as entry, i}
42
  <li class="py-5">
43
  <NewsBlock feedEntry={entry} />
44
- <div class="border-b border-gray-200 py-2"></div>
45
  </li>
46
  {/each}
47
  </ul>
 
11
  // hack to develop locally without having to run the server
12
  predictions = await fetch('static/test.json').then((d) => d.json());
13
  }
14
+ lastUpdate = new Date(predictions.last_update);
15
  predictions = predictions.entries.sort((a, b) => b.sentiment - a.sentiment);
16
+ console.log(lastUpdate, predictions);
17
  }
18
 
19
  function toggleOrder() {
 
25
  </script>
26
 
27
  <div class="px-6 py-3 max-w-4xl mx-auto">
28
+ <h1 class="text-4xl font-bold font-serif pt-5 leading-tight">The New York Times Homepage</h1>
29
+ <h3 class="text-sm leading-tight pb-5 {lastUpdate ? 'visibile' : 'invisible'}">
30
+ <b>Last Update:</b>
31
+ {lastUpdate ? lastUpdate.toLocaleString() : ''}
32
+ </h3>
33
 
34
  <button
35
+ class="{positiveOrder
36
+ ? 'bg-emerald-600'
37
+ : 'bg-red-600'} hover:bg-zinc-300 text-white font-bold py-2 px-4 rounded"
38
  on:click={toggleOrder}
39
  >
40
  {!positiveOrder ? 'Sorted by negative' : 'Sorted by positive'}
41
  </button>
 
42
  {#await fecthPredictions()}
43
+ <div class="py-4">
44
+ <svg class="animate-spin inline-block" width="25" height="25" viewBox="0 0 100 100">
45
+ <path d="M0,50 a1,1 0 0,0 100,0" fill="lightgrey" />
46
+ </svg>
47
+ Loading the NYTimes homepage feed and running sentiment analysis on titles...
48
+ </div>
49
  {:then data}
50
  <ul>
51
  {#each predictions as entry, i}
52
  <li class="py-5">
53
  <NewsBlock feedEntry={entry} />
54
+ <div class="border-b border-gray-200 py-2" />
55
  </li>
56
  {/each}
57
  </ul>