如何定期更新雅虎天气/简单派的屏幕?

发布于 2024-11-29 11:17:23 字数 1850 浏览 1 评论 0原文

我正在使用雅虎天气提要和 simplepie 来获取我的数字显示器的天气。由于它是一个在屏幕上运行的网站,我无法一直手动刷新浏览器。

我只是想知道是否有什么东西,例如 jquery 或 php doc 可以帮助我随着天气变化定期更新天气信息?如果是这样,您能给我一些如何实施的指导吗?非常感谢您的帮助。

这是我的一些代码,以防万一有用

<div id="weather">
        <div id="title">
                <ul>
                    <!--<li> Outside Temp </li>-->
                    <li> Today </li>
                    <li> Tomorrow </li>

                </ul>
        </div> <!--title-->

        <div id="forecast">

        <div id="images">
            <ul>
                <?php foreach ($weather->get_forecasts() as $forecast): ?>

                <li><img src="<?php echo $forecast->get_image(); ?>" alt="Weather" /></li>

                <?php endforeach; ?>
            </ul>
         </div> <!--images-->

        <div id="degrees">
            <ul>
                <?php foreach ($weather->get_forecasts() as $forecast): ?>

                <li><?php echo $forecast->get_low(); ?>&deg; &nbsp; <?php echo $forecast->get_high(); ?>&deg; </li>

                <?php endforeach; ?>
            </ul>
            </div><!--degrees-->

    </div> <!--forecast-->
<!--</div> <!--second-->

一些标题部分信息:

<php

require_once('simplepie/simplepie.inc');
require_once('simplepie/simplepie_yahoo_weather.inc');

$feed = new SimplePie();

$feed->set_feed_url('http://weather.yahooapis.com/forecastrss?w=1234567&u=c'); 

$feed->set_item_class('SimplePie_Item_YWeather');

$feed->init();

$weather = $feed->get_item(0);

?>

非常感谢!

小号:)

I am using yahoo weather feed and simplepie to get weather for my digital display. Since it is a website run on a screen, I can't refresh the browser all the time manually.

I am just wondering is there anything eg jquery or php doc can help me update the weather information periodically as the weather changes?? If so would you be able to give me some directions on how to implement? your help is greatly appreciated.

Here is some of my code just in case it is useful

<div id="weather">
        <div id="title">
                <ul>
                    <!--<li> Outside Temp </li>-->
                    <li> Today </li>
                    <li> Tomorrow </li>

                </ul>
        </div> <!--title-->

        <div id="forecast">

        <div id="images">
            <ul>
                <?php foreach ($weather->get_forecasts() as $forecast): ?>

                <li><img src="<?php echo $forecast->get_image(); ?>" alt="Weather" /></li>

                <?php endforeach; ?>
            </ul>
         </div> <!--images-->

        <div id="degrees">
            <ul>
                <?php foreach ($weather->get_forecasts() as $forecast): ?>

                <li><?php echo $forecast->get_low(); ?>°   <?php echo $forecast->get_high(); ?>° </li>

                <?php endforeach; ?>
            </ul>
            </div><!--degrees-->

    </div> <!--forecast-->
<!--</div> <!--second-->

Some header part info:

<php

require_once('simplepie/simplepie.inc');
require_once('simplepie/simplepie_yahoo_weather.inc');

$feed = new SimplePie();

$feed->set_feed_url('http://weather.yahooapis.com/forecastrss?w=1234567&u=c'); 

$feed->set_item_class('SimplePie_Item_YWeather');

$feed->init();

$weather = $feed->get_item(0);

?>

Thank you very much!

S:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

高跟鞋的旋律 2024-12-06 11:17:23

由于您尚未使用 JavaScript,因此定期刷新页面的一个非常简单的方法可能是使用 元刷新标签。尽管已弃用,但它可能是获取动态页面的快速方法。只需将标记添加到页面的 即可:

<meta http-equiv="refresh" content="5"> <!--Refresh the page every 5 seconds-->

但是,您可能需要考虑使用 ajax 将内容加载到页面中。这可能不是最好的方法,但这里有一些快速而肮脏的代码。

在主页中,您可以使用 jQuery load 定期访问 URL用于您的 PHP 脚本并将内容加载到 div 中进行显示:

<html>
<head>
    <script type="text/javascript">
        $(document).ready(function(){
            setTimeout(loadWeather, 5000); //using setTimeout instead of a setInterval to avoid having multiple queries queue up when the first one fails to return within the timeout period
        });

        function loadWeather(){
            $('#weather').load('weather.php);
            setTimeout(loadWeather, 5000);
        }
    </script>
</head>
<body>
    <div id="weather" />
</body>
</html>

其中 weather.php 可能如下所示:

<div id="weather">
        <div id="title">
                <ul>
                    <!--<li> Outside Temp </li>-->
                    <li> Today </li>
                    <li> Tomorrow </li>

                </ul>
        </div> <!--title-->

        <div id="forecast">

        <div id="images">
            <ul>
                <?php foreach ($weather->get_forecasts() as $forecast): ?>

                <li><img src="<?php echo $forecast->get_image(); ?>" alt="Weather" /></li>

                <?php endforeach; ?>
            </ul>
         </div> <!--images-->

        <div id="degrees">
            <ul>
                <?php foreach ($weather->get_forecasts() as $forecast): ?>

                <li><?php echo $forecast->get_low(); ?>°   <?php echo $forecast->get_high(); ?>° </li>

                <?php endforeach; ?>
            </ul>
            </div><!--degrees-->

    </div> <!--forecast-->
<!--</div> <!--second-->

Since you're not already using JavaScript, a really simple way for you to periodically refresh the page might be to use the meta refresh tag. Although deprecated, it might be a quick way for you to get dynamic pages. Simply add the tag to the <head> of the page:

<meta http-equiv="refresh" content="5"> <!--Refresh the page every 5 seconds-->

However, you might want to consider using ajax to load your content into the page instead. This might not be the best possible approach to this but here's some quick and dirty code.

In the main page, you could use jQuery load to periodically hit the URL for your PHP script and load the content into a div for display:

<html>
<head>
    <script type="text/javascript">
        $(document).ready(function(){
            setTimeout(loadWeather, 5000); //using setTimeout instead of a setInterval to avoid having multiple queries queue up when the first one fails to return within the timeout period
        });

        function loadWeather(){
            $('#weather').load('weather.php);
            setTimeout(loadWeather, 5000);
        }
    </script>
</head>
<body>
    <div id="weather" />
</body>
</html>

where weather.php might look something like this:

<div id="weather">
        <div id="title">
                <ul>
                    <!--<li> Outside Temp </li>-->
                    <li> Today </li>
                    <li> Tomorrow </li>

                </ul>
        </div> <!--title-->

        <div id="forecast">

        <div id="images">
            <ul>
                <?php foreach ($weather->get_forecasts() as $forecast): ?>

                <li><img src="<?php echo $forecast->get_image(); ?>" alt="Weather" /></li>

                <?php endforeach; ?>
            </ul>
         </div> <!--images-->

        <div id="degrees">
            <ul>
                <?php foreach ($weather->get_forecasts() as $forecast): ?>

                <li><?php echo $forecast->get_low(); ?>°   <?php echo $forecast->get_high(); ?>° </li>

                <?php endforeach; ?>
            </ul>
            </div><!--degrees-->

    </div> <!--forecast-->
<!--</div> <!--second-->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文