thegreatjavascript / 2019-nCoV-News

2019-nCoV疫情实时播报🅥|墙内传播版
MIT License
138 stars 8 forks source link

New Feature: Periodically Refresh #4

Closed Soontao closed 4 years ago

Soontao commented 4 years ago

https://github.com/thegreatjavascript/2019-nCoV-News/blob/3c8207f57d585c7160283fa6d72d57eb74526e7b/src/components/HelloWorld.vue#L65-L78

Maybe we could add a function which refresh data every 1 minute ? So that users can share it on the TV / monitor.

Be Health, Thanks. :)

whc2001 commented 4 years ago

I am not familiar with Vue, but seems like you can use setInterval?

         let api = 'https://api2019ncovnews.herokuapp.com/api'; 
         if (process.env.NODE_ENV !== 'production') { 
             api = 'http://localhost:9919/api'; 
         } 
         setInterval(function() {
             this.loading = true; 
             fetch(api) 
                 .then(res => { 
                     return res.json(); 
                 }) 
                 .then(res => { 
                     this.title = res.title; 
                     this.link = res.link; 
                     this.data = res.items; 
                     this.loading = false; 
                 }); 
         }, 300000);    // 5 minutes

However due to #1 , there is a delay (about 1~2 hour or so) between when the new message is published on Telegram and when the API response includes the new message.

shuiRong commented 4 years ago

great idea. I will update it now.

shuiRong commented 4 years ago

I am not familiar with Vue, but seems like you can use setInterval?

         let api = 'https://api2019ncovnews.herokuapp.com/api'; 
         if (process.env.NODE_ENV !== 'production') { 
             api = 'http://localhost:9919/api'; 
         } 
         setInterval(function() {
             this.loading = true; 
             fetch(api) 
                 .then(res => { 
                     return res.json(); 
                 }) 
                 .then(res => { 
                     this.title = res.title; 
                     this.link = res.link; 
                     this.data = res.items; 
                     this.loading = false; 
                 }); 
         }, 300000);    // 5 minutes

However due to #1 , there is a delay (about 1~2 hour or so) between when the new message is published on Telegram and when the API response includes the new message.

@whc2001 It does have a delay(1~2 hours). I will write another crawlar to solve this as soon as possible.

shuiRong commented 4 years ago

It's solved. (5 minutes.)