一个小小的时间插件

时间:2023-01-31 08:38:07

先上效果图

一个小小的时间插件

这个优点是不用配置数据库

一个时间插件

一个小小的时间插件

time.py代码

#!/usr/bin/env python
# -*- coding:utf-8 -*-   
import tornado.ioloop
import tornado.web        
import datetime,time
class TimeHandler(tornado.web.RequestHandler):
    def get(self):
        d1 = datetime.datetime.strptime(str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())), '%Y-%m-%d %H:%M:%S')
        d2 = datetime.datetime.strptime(open('time.log','r+').read(), '%Y-%m-%d %H:%M:%S')
        delta = d1 - d2
        bday=delta.days
        print(delta)
        self.render("time.html",a=open('time.log','r+').read(),b=bday,c=d1)
    def post(self,*args,**kwargs):
        d1 = datetime.datetime.strptime(str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())), '%Y-%m-%d %H:%M:%S')
        d2 = datetime.datetime.strptime(open('time.log','r+').read(), '%Y-%m-%d %H:%M:%S')
        delta = d1 - d2
        bday=delta.days
        print(delta)    
        a=self.get_argument('time')
        print(a)
        open('time.log','w+').write(str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
        self.render("time.html",a=open('time.log','r+').read(),b=bday,c=d1)
    
                
application = tornado.web.Application([
    (r"/time", TimeHandler),
])   
if __name__ == "__main__":
   
   application.listen(8888)
   tornado.ioloop.IOLoop.instance().start()

time.html代码

<html ng-app="ionicApp">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title>后台管理</title>
        <link href="https://cdn.bootcss.com/ionic/1.3.2/css/ionic.css" rel="stylesheet">
        <script src="https://cdn.bootcss.com/ionic/1.3.2/js/ionic.bundle.min.js"></script>
    </head>
    <body>
    
            </br>
         
    <div class="bar bar-header">
      <div class="h1 title">运行时间</div>
    </div>
    
    <div class="content has-header">

      <div class="card">
        <div class="item item-divider">
         开始时间:{{a}}
        </div>
        <div class="item item-text-wrap">
          <center><h1>{{b}}天</h1></center>
        </div>
        <div class="item item-divider">
          现在时间:{{c}}
        </div>
      </div>
   </div>
            </br>
            </br>
            </br>
                ​<form method="post" action="/time">
         <div class="padding">
        <button name='time' value='qk' class="button button-block button-positive">清零</button>
      </div>
        </form>
        
  </body>
</html>

        
        
        

  新建一个time.log文件

2012-03-05 17:41:20

 更新:

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-   
 3 import tornado.ioloop
 4 import tornado.web        
 5 import datetime,time
 6 class TimeHandler(tornado.web.RequestHandler):
 7     def get(self):
 8         f=open('time.config','r+').read()
 9         li=eval(f)
10         hours=datetime.datetime.now().strftime('%H')
11         riqi=datetime.datetime.now().strftime('%Y%m%d')
12         li.append([str(riqi),int(hours)])
13         open('time.config','w').write(str(li))
14         XXX=[int(i[0]) for i in li]
15         OOO=[i[1] for i in li]
16         print(XXX)
17         print(OOO)
18         d1 = datetime.datetime.strptime(str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())), '%Y-%m-%d %H:%M:%S')
19         d2 = datetime.datetime.strptime(open('time.log','r+').read(), '%Y-%m-%d %H:%M:%S')
20         delta = d1 - d2
21         print(d1)
22         bday=delta.days
23         print(delta)
24         self.render("滑动.html",a=open('time.log','r+').read(),b=bday,c=d1,l0=str(XXX),l1=str(OOO))
25         
26     def post(self,*args,**kwargs):
27         d1 = datetime.datetime.strptime(str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())), '%Y-%m-%d %H:%M:%S')
28         d2 = datetime.datetime.strptime(open('time.log','r+').read(), '%Y-%m-%d %H:%M:%S')
29         delta = d1 - d2
30         bday=delta.days
31         print(delta)    
32         a=self.get_argument('time')
33         f=open('time.config','r+').read()
34         print(f)
35         print(a)
36         open('time.log','w+').write(str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
37         self.render("time.html",a=open('time.log','r+').read(),b=bday,c=d1)
38         
39                 
40 application = tornado.web.Application([
41     (r"/time", TimeHandler),
42 ])   
43 if __name__ == "__main__":
44    
45    application.listen(8888)
46    tornado.ioloop.IOLoop.instance().start()

 time_p.html

  1 <html>
  2     <head>
  3     <meta charset="utf-8">
  4     <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
  5     <title>网站运行时间</title>
  6     <link href="https://cdn.bootcss.com/ionic/1.3.2/css/ionic.css" rel="stylesheet">
  7     <script src="https://cdn.bootcss.com/ionic/1.3.2/js/ionic.bundle.min.js"></script>
  8     <script type="text/javascript">
  9      angular.module('starter', ['ionic'])
 10 
 11       .run(function($ionicPlatform) {
 12         $ionicPlatform.ready(function() {
 13           // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
 14           // for form inputs)
 15           if(window.cordova && window.cordova.plugins.Keyboard) {
 16             cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
 17           }
 18           if(window.StatusBar) {
 19             StatusBar.styleDefault();
 20           }
 21         });
 22       })
 23 
 24       .controller( 'actionsheetCtl',['$scope',function($scope){
 25 
 26           $scope.devList = [
 27               { text: "HTML5", checked: true },
 28               { text: "CSS3", checked: false },
 29               { text: "JavaScript", checked: false }
 30             ];
 31 
 32             $scope.pushNotificationChange = function() {
 33               console.log('Push Notification Change', $scope.pushNotification.checked);
 34             };
 35 
 36             $scope.pushNotification = { checked: true };
 37             $scope.emailNotification = 'Subscribed';
 38 
 39       }])
 40     </script>
 41     <style type="text/css">
 42     body {
 43       cursor: url('https://www.runoob.com/try/demo_source/finger.png'), auto;
 44     }
 45     </style>
 46     </head>
 47      <body ng-app="starter" ng-controller="actionsheetCtl" >
 48 
 49 
 50 
 51       <ion-content>
 52     
 53 <div class="content has-header">
 54 
 55       <div class="card">
 56         <div class="item item-divider">
 57          开始时间:{{a}}
 58         </div>
 59         <div class="item item-text-wrap">
 60           <center><h1>{{b}}天</h1></center>
 61         </div>
 62         <div class="item item-divider">
 63           现在时间:{{c}}
 64         </div>
 65       </div>
 66    </div>
 67             </br>
 68             </br>
 69             </br>
 70<form method="post" action="/time">
 71          <div class="padding">
 72         <button name='time' value='qk' class="button button-block button-positive">清零</button>
 73       </div>
 74         </form>
 75 
 76       <body style="height: 70%; margin: 0">
 77        <div id="container" style="height: 100%"></div>
 78        <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/echarts.min.js"></script>
 79        <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-gl/echarts-gl.min.js"></script>
 80        <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts-stat/ecStat.min.js"></script>
 81        <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/dataTool.min.js"></script>
 82        <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/china.js"></script>
 83        <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/map/js/world.js"></script>
 84        <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZUONbpqGBsYGXNIYHicvbAbM"></script>
 85        <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/echarts/extension/bmap.min.js"></script>
 86        <script type="text/javascript" src="http://echarts.baidu.com/gallery/vendors/simplex.js"></script>
 87        <script type="text/javascript">
 88 var dom = document.getElementById("container");
 89 var myChart = echarts.init(dom);
 90 var app = {};
 91 option = null;
 92 option = {
 93     xAxis: {
 94         type: 'category',
 95         data: {{l0}}
 96     },
 97     yAxis: {
 98         type: 'value'
 99     },
100     series: [{
101         data: {{l1}},
102         type: 'line'
103     }]
104 };
105 ;
106 if (option && typeof option === "object") {
107     myChart.setOption(option, true);
108 }
109        </script>
110    </body>
111    
112    
113 
114       </ion-content>
115 
116     </body>
117 </html>