#!/usr/local/python2.7/bin/python
# -*- coding:utf-8 -*-
#file:check_list_game.py
#create file 'songxs'
#blog:kukafei520.net

from multiprocessing import Process
import re,sys,urllib,codecs,os
import string
import json,codecs
import smtplib
from email.mime.text import MIMEText
#############
mailto_list=["voilet@qq.com"]
#####################
#设置服务器,用户名、口令以及邮箱的后缀
mail_host="xxxxx.qq.com"
mail_user="用户名"
mail_pass="密码"
mail_postfix="qq.com"
######################
def send_mail(to_list,sub,content):
    me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
    msg = MIMEText(content)
    msg['Subject'] = sub
    msg['From'] = me
    msg['To'] = ";".join(to_list)
    try:
        s = smtplib.SMTP()
        s.connect(mail_host)
        s.login(mail_user,mail_pass)
        s.sendmail(me, to_list, msg.as_string())
        s.close()
        return True
    except Exception, e:
        print str(e)
        return False
# Game:
game_url = ['http://game.funshion.com/door.php?source=duilian',
            'http://game.funshion.com/index/game/index.php?c=web&a=ajax_recent_login_servers&cache=1343619052',
            'http://game.funshion.com/index/account/index.php?c=index&a=member_center',
            'http://game.funshion.com/index/account/index.php?c=index&a=global_login&location=http://game.funshion.com/index/account/index.php?c=index&a=member_center',
            'http://game.funshion.com/index/account/index.php?c=index&a=global_register&location=/bbs/space.php?uid=39666611',
            'http://game.funshion.com/content/gonghui/formhtml.html',
            'http://game.funshion.com/bbs/',
            'http://game.funshion.com/bbs/logging.php?action=login',
            'http://game.funshion.com/bbs/forumdisplay.php?fid=226',
            'http://game.funshion.com/bbs/viewthread.php?tid=325790&extra=page%3D1',
            'http://game.funshion.com/bbs/space.php?uid=40381815',
            'http://pay.funshion.com/account/account.php?module=account&opt=view_trade_record',
            ]
#定义类
def game_list_code():
    game_code_url = urllib.urlopen('http://game.funshion.com/index/game/index.php?c=web&a=index_recommend&gc=smxj&cache=1343618612').read()
    code_id=json.loads(game_code_url)['code']
    if int(code_id) == 200:
        print json.loads(game_code_url)['server']
    else:
        print "游戏服务器列表页请求失败"
        if send_mail(mailto_list,"游戏获取服务器列表",'游戏获取服务器列表'):
            print "发送成功"
        else:
            print "发送失败"
class Work(object):
    def __init__(self,url):
        self.url = url
    def worker(self):
        str_res = ""
        game_code = urllib.urlopen(self.url)
        code_url = self.url
        if game_code.code == 200:
            str_res +='%s %s %s '  % (game_code.code,' | 服务正常 | ',self.url,)
        else:
            game_code_info = game_code.info()
            str_res +='%s %s %s %s '  % (game_code.code,' | 游戏服务器异常 | ',self.url,game_code_info)
            if send_mail(mailto_list,"增值检测异常",str_res):
                print "发送成功"
            else:
                print "发送失败"
        print str_res

def game():
    num=0
    threads=[]
    for line in  game_url:
        line = line.strip()
        work = Work(line)
        p= Process(target=work.worker)
        threads.append(p)
        num+=1
    for i in range(num):
        threads[i].start()
    for i in range(num):
        threads[i].join()

if __name__ == "__main__":
    game(),game_list_code()

http_code



分享到: 更多

这篇日志的 QR 二维码为:

三月 5th, 2013

Posted In: 网络技术

发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量