代码基于Python3.3.3,PyQt5.1.1

复制代码 代码如下:
# -*- coding: utf-8 -*-
# Python 3.3.3
# PyQt 5.1.1
import sys,time,re,urllib.parse,urllib.request,http.cookiejar,json
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

"""cookie"""
cookie=http.cookiejar.LWPCookieJar()
#cookie.load('f:/cookie.txt',True,True)
chandle=urllib.request.HTTPCookieProcessor(cookie)

"""获取数据"""
def getData(url):
    r=urllib.request.Request(url)
    opener=urllib.request.build_opener(chandle)
    u=opener.open(r)
    #chandle.cookiejar.save('f:/cookie.txt',True,True)
    data=u.read()
    try:
        data=data.decode('utf-8')
    except:
        data=data.decode('gbk','ignore')
    return data
def postData(url,data):
    data=urllib.parse.urlencode(data);data=bytes(data,'utf-8')
    r=urllib.request.Request(url,data)
    opener=urllib.request.build_opener(chandle)
    u=opener.open(r)
    #chandle.cookiejar.save('f:/cookie.txt',True,True)
    data=u.read()
    try:
        data=data.decode('utf-8')
    except:
        data=data.decode('gbk','ignore')
    return data
"""火车票"""
class Ticket:
    def init(self,s,e,d):
        self.li=[]
        cont=getData('https://kyfw.12306.cn/otn/resources/js/framework/station_name.js')
        s=re.findall('%s\|([^|]+)' % s,cont)[0]
        e=re.findall('%s\|([^|]+)' % e,cont)[0]
        url='https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=0X00&queryDate=%s&from_station=%s&to_station=%s' % (d,s,e)
        cont=json.loads(getData(url))["data"]["datas"]
        name=[
            "station_train_code",
            "from_station_name",
            "to_station_name",
            "lishi",
            "swz_num",
            "tz_num",
            "zy_num",
            "ze_num",
            "gr_num",
            "rw_num",
            "yw_num",
            "rz_num",
            "yz_num",
            "wz_num",
            "qt_num"
        ]
        for x in cont:
            tmp=[]
            for y in name:
                if y=="from_station_name":
                    s=x[y]+'\n'+x["start_time"]
                    tmp.append(s)
                elif y=="to_station_name":
                    s=x[y]+'\n'+x["arrive_time"]
                    tmp.append(s)
                else:
                    tmp.append(x[y])
            self.li.append(tmp)
"""ui"""
class Dialog(QDialog):
    ticket=Ticket()
    def __init__(self):
        super().__init__()
        self.resize(750,350)
        #布局管理器
        self.layout=[QVBoxLayout(self),QHBoxLayout()]
        self.layout[1].setContentsMargins(0,0,0,0)
        self.layout[1].setSpacing(0)
        self.layout[0].setContentsMargins(0,0,0,0)
        self.layout[0].setSpacing(0)
        self.layout[0].addLayout(self.layout[1])
        #按钮
        btn=QPushButton("ok")
        btn.clicked.connect(self.submit)
        #输入选项
        label=[QLabel("发站:"),QLabel("到站:"),QLabel("日期:")]
        self.line=[QLineEdit(),QLineEdit(),QComboBox()]
        y=int(time.strftime("%Y",time.localtime()))
        m=int(time.strftime("%m",time.localtime()))
        d=int(time.strftime("%d",time.localtime()))
        i=0
        yy=y
        mm=m
        dd=d
        while i<20:
            if m in (1,3,5,7,8,10,12):
                if d+i>31:
                    dd=d+i-31
                    mm=m+1
                    if mm>12:
                        yy=y+1
                        mm=mm-12
                else:
                    dd=d+i
            elif m in (4,6,9,11):
                if d+i>30:
                    dd=d+i-30
                    mm=m+1
                    if mm>12:
                        yy=y+1
                        mm=mm-12
                else:
                    dd=d+i
            else:
                if (m%400==0) or ((m%4==0) and (m%100!=0)):
                    if d+i>29:
                        dd=d+i-29
                        mm=m+1
                        if mm>12:
                            yy=y+1
                            mm=mm-12
                    else:
                        dd=d+i
                else:
                    if d+i>28:
                        dd=d+i-28
                        mm=m+1
                        if mm>12:
                            yy=y+1
                            mm=mm-12
                    else:
                        dd=d+i
            s='%d-%02d-%02d' % (yy,mm,dd)
            self.line[2].addItem(s)
            i+=1
        i=0
        while i<3:
            self.line[i].setMaximumWidth(100)
            label[i].setMaximumWidth(50)
            label[i].setAlignment(Qt.AlignRight|Qt.AlignVCenter)
            self.layout[1].addWidget(label[i],Qt.AlignRight)
            self.layout[1].addWidget(self.line[i],Qt.AlignLeft)
            i+=1
        self.layout[1].addWidget(btn)
        #表格
        head=['车次','发站','到站','历时','商务座','特等座','一等座','二等座','高级软卧','软卧','硬卧','软座','硬座','无座','其他']
        self.table=QTableWidget()
        self.table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.table.setColumnCount(15)
        self.table.setHorizontalHeaderLabels(head)
        self.layout[0].addWidget(self.table)
        self.show()
    def submit(self):
        self.table.clearContents()
        s=self.line[0].text()
        e=self.line[1].text()
        d=self.line[2].currentText()
        self.ticket.init(s,e,d)
        self.table.setRowCount(len(self.ticket.li))
        i=0
        for x in self.ticket.li:
            j=0
            for y in x:
                if j==1 or j==2:
                    item=QLabel(y)
                    item.setAlignment(Qt.AlignCenter)
                    self.table.setCellWidget(i,j,item)
                else:
                    item=QTableWidgetItem(y)
                    item.setTextAlignment(Qt.AlignCenter)
                    if not re.search('\D',y):
                        item.setForeground(QBrush(Qt.red))
                    self.table.setItem(i,j,item)
                if j>2 or j==0:
                    self.table.resizeColumnToContents(j)
                j+=1
            i+=1
if __name__=="__main__":
    app=QApplication(sys.argv)
    dialog=Dialog()
    sys.exit(app.exec_())

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。