1.时间操作
//获取当前时间 格式是%Y-%m-%d %H:%M:%S
currTime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
//获取前一天日期格式为%Y-%m-%d
yesterday = datetime.date.today() - datetime.timedelta(days=1)
//获取前一个小时日期
yesterday = (datetime.datetime.now() - datetime.timedelta(hours = 1)).strftime("%Y-%m-%d %H:%M:%S")

2.mysql 操作

#!/usr/bin/python
#coding=utf-8
import MySQLdb
import datetime
import MailUtil
import time
try:
   connection = MySQLdb.connect(user="entdb",passwd="dm6db+1de@v",host="192.168.32.47",db="miss8")
except:
   print "Could not connect to MySQL server."
   exit( 0 )

print "----------------------------贵圈新闻数据流 check start------------------------------"
mailto_list=['xubaolong@iminer.com','yueyaobiao@iminer.com']
try:
        while True:
                cursor = connection.cursor()
                currTime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
                #两小时前时间
                two_hours_ago = (datetime.datetime.now() - datetime.timedelta(hours = 2)).strftime("%Y-%m-%d %H:%M:%S")
                #明星和电影前一天微指数抓取
                cursor.execute( "SELECT count(1)  from gquan_article_info  where crawl_time>'"+str(two_hours_ago)+"'" )
                results = cursor.fetchall();
                count = 0
                for row in results:
                        count = row[0]

print "INFO\t当前时间: " + str(currTime) + "\t前两小时抓取数量是:" +str(count)

if count == 0:
                        tag =  MailUtil.send_mail(mailto_list,'贵圈新闻数据流出现问题两小时之内没有数据','贵圈新闻数据流出现问题,请检查(47 数据库gquan_article_info)请尽快修复!!!!!!')
                        if tag:
                                print "ERROR\t当前时间:" + str(currTime) + "\t贵圈新闻数据流出现问题\t邮件发送成功"
                        else:
                                print "ERROR\t当前时间: " + str(currTime) + "\t贵圈新闻数据流出现问题\t邮件发送失败"
                else:
                        print "INFO\t当前时间:" + str(currTime) + "\t贵圈新闻数据流一切正常\t无须发送邮件"
                cursor.close()
                print "INFO\t当前时间:" + str(currTime) + "\t小e需要休息一小时!!!!!!"
                #睡一个小时
                time.sleep(1 * 60 * 60 )
except:
   print "Exception"
   exit( 0 )
print "----------------------------贵圈新闻数据流 check over------------------------------"

3.异常跟踪

Python 数据库连接的时候,报异常:ImportError: No module named release

Linux Fedora, CentOS系统:yum install MySQL-python 即可

4.mysql操作获取数量

#获取[昨天电影热度值符合规范]的数量
   cursor.execute( "select count(*) from domain_movie_hot_records where record_date = '"+str(yesterday)+"' and news_num > 0" )
   result = cursor.fetchone();
   yesterday_movie_correct_hot_count = result[0]

python常用脚本以及问题跟踪的更多相关文章

  1. ArcGis Python常用脚本

    ArcGis Python脚本——ArcGIS 中使用的 Python 是什么版本 ArcGis Python脚本——批量添加字段 ArcGis Python脚本——批量删除字段 ArcGis Pyt ...

  2. 常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript

    常用脚本语言Perl,Python,Ruby,Javascript一 Perl,Python,Ruby,Javascript Javascript现阶段还不适合用来做独立开发,它的天下还是在web应用 ...

  3. 转:python常用运维脚本实例

    python常用运维脚本实例 转载  file是一个类,使用file('file_name', 'r+')这种方式打开文件,返回一个file对象,以写模式打开文件不存在则会被创建.但是更推荐使用内置函 ...

  4. python常用运维脚本实例【转】

    file是一个类,使用file('file_name', 'r+')这种方式打开文件,返回一个file对象,以写模式打开文件不存在则会被创建.但是更推荐使用内置函数open()来打开一个文件 . 首先 ...

  5. Python常用的标准库以及第三方库

    Python常用的标准库以及第三方库有哪些?   20个必不可少的Python库也是基本的第三方库 读者您好.今天我将介绍20个属于我常用工具的Python库,我相信你看完之后也会觉得离不开它们.他们 ...

  6. python常用库(转)

    转自http://www.west999.com/info/html/wangluobiancheng/qita/20180729/4410114.html Python常用的库简单介绍一下 fuzz ...

  7. Python常用的库简单介绍一下

    Python常用的库简单介绍一下fuzzywuzzy ,字符串模糊匹配. esmre ,正则表达式的加速器. colorama 主要用来给文本添加各种颜色,并且非常简单易用. Prettytable ...

  8. MS SQL 日常维护管理常用脚本(二)

    监控数据库运行 下面是整理.收集监控数据库运行的一些常用脚本,也是MS SQL 日常维护管理常用脚本(一)的续集,欢迎大家补充.提意见. 查看数据库登录名信息   Code Snippet SELEC ...

  9. Python常用模块之sys

    Python常用模块之sys sys模块提供了一系列有关Python运行环境的变量和函数. 常见用法 sys.argv 可以用sys.argv获取当前正在执行的命令行参数的参数列表(list). 变量 ...

随机推荐

  1. ARTS Challenge- Week 1 (2019.03.25~2019.03.31)

    1.Algorithm - at least one leetcode problem per week(Medium+) 986. Interval List Intersections https ...

  2. vijos搭建踩坑

    nodejs我用的8.x版本,可以工作. 和制作组交谈之后他们说最好榨汁机和主机不要在同一系统下. vj4/vj4/handler/base.py的第343行 从 super(Connection, ...

  3. sql server 2012 减少日志

    USE [master] GO ALTER DATABASE 数据库名 SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE 数据库名 SET RECO ...

  4. Three.js学习笔记05

    场景相关函数和属性 下面的代码中应用到了所有以上的函数及属性: <!DOCTYPE html> <html lang="en"> <head> ...

  5. proxy_pass根据path路径转发时的"/"问题记录

    在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/.当加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理 ...

  6. [Swift]LeetCode25. k个一组翻转链表 | Reverse Nodes in k-Group

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k  ...

  7. [Swift]LeetCode142. 环形链表 II | Linked List Cycle II

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note ...

  8. [Swift]LeetCode190. 颠倒二进制位 | Reverse Bits

    Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 ...

  9. [Swift]LeetCode338. 比特位计数 | Counting Bits

    Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the ...

  10. [Swift]LeetCode754. 到达终点数字 | Reach a Number

    You are standing at position 0 on an infinite number line. There is a goal at position target. On ea ...