服务器过保日期批量查询python

浪潮服务器过保查询


import json
import urllib
import requests
 
# def chenck_hardware_info(sn):
url = 'https://www.inspur.com/eportal/ui'
sn_file = "/tm/sn.text"
def request_datatime(sn):
 params = {
    "struts.portlet.action": "/portlet/download-front!serverConfig.action",
    "sn": sn,
    "src": "inspur",
    "language": "CN",
    "pageId": "2317460",
    "moduleId": "82efecfc33da48b4a66567cb3dcbe5f3"
 }
 headers = {
    "Referer": "https://www.inspur.com/eportal/ui?pageId=2317460",
    "Cookie": "JSESSIONID=****; ........(这里写cookie地址)"
 }
 r = requests.post(url, headers=headers, params=urllib.parse.urlencode(params))
 resp = r.text[1:len(r.text)-1]
 resp = json.loads(resp)
 #print(resp['Date'])
 return resp['warranty1']
 
 
def post_info(sn):
        r1 = request_datatime(sn)
        url = "http://cmdbbackend.dev.tujia.com/api/inventoryitem/sn/update/life"
        headers = {
          "OPS-Token":"IHmioqYhb0XgBAsEiHeK_guibinw",
          "Content-Type":"application/json"
        }
        data = [{
          "serialNo": sn,
          "contractPeriod": r1
        }]
        r = requests.post(url=url, headers=headers, data=json.dumps(data))
        print(sn)
        return r
 
for sn in open(sn_file, mode='r'):
    sn = sn.strip('\n')
    print(post_info(sn))


Dell服务器过保查询


import requests,re
from requests.exceptions import RequestException
from bs4 import BeautifulSoup
import json
sn_text = "/tmp/sn.text"
 
def getServiceTag(sn):
    base_url='https://www.dell.com/support/home/cn/zh/cnbsd1/product-support/servicetag/'
    html1 =  Get_Page(base_url + sn)
    if html1:
        p1 = re.compile('servicetag/(.*)/overview"')
        p2 = re.compile('<h1 class="mb-3 mb-lg-1 text-center text-lg-left position-relative word-break">(.*)</h1>')
        r1 = p1.findall(html1)
        r2 = p2.findall(html1)
        return r1
 
def Get_Page(url):      #根据sn号获取返回页面
    try:
        headers = {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36',
            'Referer': 'https://www.dell.com/support/home/cn/zh/cnbsd1/product-support/servicetag/B7WHC92'
        }
        response = requests.get(url=url,headers=headers)
        if response.status_code == 200:
            return response.text
        return None
    except RequestException:
        return None
 
def getDellInfoDetails(serviceTag,session):
    headers = {
        'Accept': '*/*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN',
        'User-Agent': 'ApiPOST Runtime +https://www.apipost.cn',
    }
    url_params = {'serviceTag': serviceTag}
    c = requests.cookies.RequestsCookieJar()
    c.set('DellCEMSession', session, path='/', domain='.dell.com')
    res = requests.post(
        url='https://www.dell.com/support/components/dashboard/cn/zh/cnbsd1/Warranty/GetWarrantyDetails',
        data=url_params, headers=headers, cookies=c)
    return res.text
 
 

def strip1(sn):
    sn = sn
    h1 = getDellInfoDetails(getServiceTag(sn), '{这里写sessionid})
    soup = BeautifulSoup(h1, 'html.parser')
    tbody = soup.find("tbody")
    try:
 
        headings = [th.get_text() for th in tbody.find_all("tr")]
        headings1 = [i for i, x in enumerate(headings) if x.find('仅限部件保修') != -1]
        headings = [th.get_text() for th in tbody.find_all("tr")]
        headings1 = [i for i, x in enumerate(headings) if x.find('仅限部件保修') != -1]
        headings2 = headings[headings1[0]].split( )
        month1 = headings2[-5].split( )
        month2 = headings2[-2].split( )
        test1 = [month1[0].replace('月', '', 3)]
        test2 = [month2[0].replace('月', '', 3)]
        l1 = headings2[-1] + '/' + test2[0] + '/' + headings2[-3]
        return l1
    except AttributeError :
        return None
 
def post_info(sn):
    r1 = strip1(sn)
    url = "http://cmdbbackend.dev.tujia.com/api/inventoryitem/sn/update/life"
    headers = {
        "OPS-Token": "IHmioqYhb0XgBAsEiHeK_guibinw",
        "Content-Type": "application/json"
    }
    data = [{
        "serialNo": sn,
        "contractPeriod": r1
    }]
    r = requests.post(url=url, headers=headers, data=json.dumps(data))
    print(sn)
    return r
 
for sn in open(sn_text, mode='r'):
    sn = sn.strip('\n')
    print(post_info(sn)
>> Home

51ak

2021/10/09

Categories: 运维 自动化 python Tags: 整理 基础

《数据库工作笔记》公众号
扫描上面的二维码,关注我的《数据库工作笔记》公众号